tags:

views:

140

answers:

1

I'm new in soapclient, I have tried to do some study online and also tried coding on soap, but seem this is still not working to me, just wandering anyone here can point out and perhaps give me some example how can I actually use the soapclint to get the feedback from the following web server?

POST /webservices/tempconvert.asmx HTTP/1.1
Host: www.w3schools.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/CelsiusToFahrenheit"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  <soap:Body>
    <CelsiusToFahrenheit xmlns="http://tempuri.org/"&gt;
      <Celsius>string</Celsius>
    </CelsiusToFahrenheit>
  </soap:Body>
</soap:Envelope>

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  <soap:Body>
    <CelsiusToFahrenheitResponse xmlns="http://tempuri.org/"&gt;
      <CelsiusToFahrenheitResult>string</CelsiusToFahrenheitResult>
    </CelsiusToFahrenheitResponse>
  </soap:Body>
</soap:Envelope>



<?php
$url = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
$client = new SoapClient($url);


?>

What should I do for the next steps so that I can get the respond ??

+1  A: 

You first have to instanciate the SoapClient class, like you did :

$url = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
$client = new SoapClient($url);


Then, you have to call the method you want to use -- the methods names can be found in the WSDL.

For instance, we could call a method called CelsiusToFahrenheit, in this WebService :

$result = $client->CelsiusToFahrenheit( /* PARAMETERS HERE */ );


Now, the problem is to know which paramaters should be passed ; and how...

If you look at the WSDL, you'll see this portion :

<s:element name="CelsiusToFahrenheit">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="Celsius" type="s:string" />
    </s:sequence>
  </s:complexType>
</s:element>

Which indicates that this methods should be passed an array, containing 1 item, which would have "Celsius" as key, and the value to convert as value.

Which means you'd have to use this portion of PHP code :

$result = $client->CelsiusToFahrenheit(array('Celsius' => '10'));


Executing this call, and dumping the result :

var_dump($result);

Gets out this kind of output :

object(stdClass)#2 (1) {
  ["CelsiusToFahrenheitResult"]=>
  string(2) "50"
}


Which means you have to use this :

echo $result->CelsiusToFahrenheitResult . "\n";

To get the resulting value :

50


Note : the structure of this result can be found in the WSDL file too, of course -- see the CelsiusToFahrenheitResponse portion.

Pascal MARTIN
@Pascal MARTIN you are the superman... thanks for the example... now i know much better how the soapclient work. THANKS :)
Jin Yong
You're welcome :-) Have fun !
Pascal MARTIN
@Pascal MARTIN I facing some issue for saop again.. not sure whether you know what is going wrong with my code? Please clikc on this link for the issue http://stackoverflow.com/questions/2619519/soap-client-not-working-in-php thanks
Jin Yong