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.

1/29/2013 12:53:38 PM

Accepted Answer

I've had great success with wsdl2php. It will automatically create wrapper classes for all objects and methods used in your web service.

10/23/2014 7:04:18 PM

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow