Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to easily consume a web service from PHP

Is there available any tool for PHP which can be used to generate code for consuming a web service based on its WSDL? Something comparable to clicking "Add Web Reference" in Visual Studio or the Eclipse plugin which does the same thing for Java.

like image 246
Edo Avatar asked Aug 07 '08 05:08

Edo


People also ask

How do I hit a webservice in my browser?

You just need to provide the Web Service URL, select POST, set the proper content-type header (text/xml, application/soap+xml, etc.), and provide the proper xml soap body in the request. Click Send.

What is SoapClient PHP?

Description ¶ This is a low level API function that is used to make a SOAP call. Usually, in WSDL mode, SOAP functions can be called as methods of the SoapClient object. This method is useful in non-WSDL mode when soapaction is unknown, uri differs from the default or when sending and/or receiving SOAP Headers.


1 Answers

In PHP 5 you can use SoapClient on the WSDL to call the web service functions. For example:

$client = new SoapClient("some.wsdl"); 

and $client is now an object which has class methods as defined in some.wsdl. So if there was a method called getTime in the WSDL then you would just call:

$result = $client->getTime(); 

And the result of that would (obviously) be in the $result variable. You can use the __getFunctions method to return a list of all the available methods.

like image 176
davidmytton Avatar answered Sep 21 '22 09:09

davidmytton