Hi all ,

I have a wevservice link say http://abc.com/wscom/MKWebService.rem from where I am trying to return value giving some parameters . The method and parameters are given below.

method : GetInfo

Parameters:

string LicenseID
string password

Return Value:

struct AnswerInt

Now I have two xml files request.xml and response.xml as

//request.xml

<?xml version="1.0" encoding="utf-8"?>
POST /dotnet/lodge.asmx HTTP/1.1
Host: www.messagenet.com.au
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <LodgeMessage xmlns="http://abc.com/wscom/MKWebService.rem">
      <LicenceID>string</LicenceID>
      <password>string</password>
     </LodgeMessage>
  </soap12:Body>
</soap12:Envelope>

//response.xml

<?xml version="1.0" encoding="utf-8"?>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <LodgeMessageResponse xmlns="http://abc.com/wscom/MKWebService.rem">
      <LodgeMessageResult>string</LodgeMessageResult>
    </LodgeMessageResponse>
  </soap12:Body>
</soap12:Envelope>

//and php file rpc.php code is :
<php

$client = new SoapClient("http://abc.com/wscom/MKWebService.rem");
    $licenceid="LicenseID";
    $password="password";

    $result = $client->LodgeMessage(array(
        "LicenceID" => $licenceid,
        "password" => $password,
    ));


    $response_arr = objectToArray($result);

    echo "return_code= " . str_replace(";", "", $response_arr["LodgeMessageResult"]);

    function objectToArray($d)
    {
        if (is_object($d))
        {
            $d = get_object_vars($d);
        }

        if (is_array($d))
        {
            return array_map(__FUNCTION__, $d);
        }
        else
        {
            return $d;
        }
    }

?>

Error:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load

How to resolve this . Urgent

Subrata

Line 38 needs to point to the WSDL, which is usually an URL ending with ?wsdl

Pritaeas ,

Thank you for your answer but I tested with ?wsdl but giving the error "Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://abc.com/wscom/MKWebService.rem?wsdl' : Extra content at the end of the document "

Subrata

No pritaeas that is dummy link

Extra content at the end of the document

The above error indicates that the WSDL is invalid.

Hi pritaeas ,
This is based on xml-rpc code . Here is the code and parameters.

method : GetInfo

Parameters:

string LicenseID
string password

Return Value:

struct AnswerInt

and the code is :

<?php
    class XmlRpcClient
    {
        protected $_url;
        protected $_namespace;
        protected $_clients;

        public function __construct( $url, $namespace = '' )
        {
            $this->_url       = (string)$url;
            $this->_namespace = (string)$namespace;
            $this->_clients   = array();
        }

        public function __get( $namespace )
        {
            if( !key_exists( $namespace, $this->_clients ) )
                $this->_clients[ $namespace ] = new XmlRpcClient( $this->_url, strlen( $this->_namespace ) > 0 ? "$this->_namespace.$namespace" : $namespace );

            return $this->_clients[ $namespace ];
        }

        public function __call( $method, array $parameters = array() )
        {
            $request = xmlrpc_encode_request( strlen( $this->_namespace ) > 0 ? "$this->_namespace.$method" : $method, $parameters );
            $context = stream_context_create(
                array(
                    'http' => array(
                        'method'  => "POST",
                        'header'  => "Content-Type: text/xml",
                        'content' => $request
                    )
                )
            );

            $file       = file_get_contents( $this->_url, false, $context );
            $response = xmlrpc_decode( $file );

           /* if( !$response )
                throw new XmlRpcClientException( array( 'faultString' => 'Invalid response from ' . $this->_url ) );

            if( xmlrpc_is_fault( $response ) )
                throw new XmlRpcClientException( $response );*/

            return $response;
        }
    }

    /**
     * Will be thrown by XmlRpcClient on faults.
     */
    class XmlRpcClientException extends Exception
    {
        public function __construct( $response )
        {
            parent::__construct( $response[ 'faultString' ], $response[ 'faultCode' ] );
        }
    }

    $rpc  = new XmlRpcClient( "http://abc.com/wscom/MKWebService.rem " );

    $data = $rpc->tarocards->LicenseAnswerInt("id123","subrata");

    var_dump( $data );

?>

this is not wsdl supported. Now what can I do ?

Subrata

Sorry, never used XmlRpcClient before, and no way of testing this. If you use SoapUI, do you get a response then?

Pritaeas ,

It is done and code is as follows :

//info.php

<h4>Get license Info</h4>
<table bgcolor="#CCCCCC" cellspacing="0" cellpadding="0">
<form name="GetLicensefrm" action="rpc-process.php" method="post">
    <tr>
       <td>LicensiID:</td>
       <td><input name="licenseid" id="licenseid" /></td>
    </tr>
    <tr>
       <td>Password:</td>
       <td><input type="text"  name="password" id="password"></td>
    </tr>
    <tr>
       <td><input type="Submit" value="Execute" >
           <input type="hidden" name="todo" id="todo" value="getlicense" /></td>
       <td>&nbsp; </td>
    </tr>
</form>
</table>

//rpc-process.php

$varlicenseid=$_POST['licenseid'];
    $varpassword=$_POST['password'];
    $request = xmlrpc_encode_request("GetLicenseInfo", array($varlicenseid,$varpassword));
    $context = stream_context_create(array('http' => array(
      'method' => "POST",
      'header' => "Content-Type: text/xml",
      'content' => $request
    )));
    $file = file_get_contents("http://abc.com/as_com/menWebService.rem", false, $context);
    $response = xmlrpc_decode($file);
    if ($response && xmlrpc_is_fault($response)) 
     {
     trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
     } 
    else 
        {
        var_dump($response);
    // print_r($response);

      }
    }

but I want the response in xml format and instread of var_dump($response); this will return in struct format.

Subrata

Perhaps the webservice has an option to request xml. What do you mean by struct format? Can you show an example response.

Two Parameters passed to return struct type xml file.

//output is  :
array
  'Answer' => int -1
  'License' => 
    array
      'product' => string '' (length=0)

  'Comment' => string ''jhgjhgjhg (length=37)

Will soapUI support xml-rpc ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.