How to make SoapClient in php

I'm new to soapclient, I tried to do some research on the internet, and also tried coding on soap, but it doesn't seem to work for me yet, just wandering around who can point here, and maybe give me an example of how Am I really using soapclint to get 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/">
  <soap:Body>
    <CelsiusToFahrenheit xmlns="http://tempuri.org/">
      <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/">
  <soap:Body>
    <CelsiusToFahrenheitResponse xmlns="http://tempuri.org/">
      <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 answer?

+5
source share
1 answer

First you need to create a classSoapClient , just like you:

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


Then you must call the method you want to use . Method names can be found in WSDL.

, CelsiusToFahrenheit WebService:

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


, , ; ...

WSDL, :

<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>

, , 1 , "Celsius" , .

, PHP:

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


:

var_dump($result);

:

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


, :

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

:

50


: WSDL - . CelsiusToFahrenheitResponse.

+10

All Articles