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.

This question is tagged with php web-services visual-studio wsdl

~ Asked on 2008-08-07 05:48:33

7 Answers


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

~ Answered on 2008-08-15 18:36:14


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.

~ Answered on 2008-08-23 18:54:21


I have used NuSOAP in the past. I liked it because it is just a set of PHP files that you can include. There is nothing to install on the web server and no config options to change. It has WSDL support as well which is a bonus.

~ Answered on 2008-08-13 13:54:10


This article explains how you can use PHP SoapClient to call a api web service.

~ Answered on 2011-07-26 09:17:30


Well, those features are specific to a tool that you are using for development in those languages.

You wouldn't have those tools if (for example) you were using notepad to write code. So, maybe you should ask the question for the tool you are using.

For PHP:

~ Answered on 2008-08-07 07:17:55


Say you were provided the following:

<x:Envelope xmlns:x="" xmlns:int="">


<s:Envelope xmlns:s="">
    <s:Body xmlns:xsi="" xmlns:xsd="">
        <authenticateLoginResponse xmlns="">

Let's say that accessing said that the WSDL address is:

$client = new SoapClient('');
$result = $client->authenticateLogin(array('LoginId' => 12345));
if (!empty($result->authenticateLoginResult->RequestStatus)
    && !empty($result->authenticateLoginResult->UserName)) {
    echo 'The username is: '.$result->authenticateLoginResult->UserName;

As you can see, the items specified in the XML are used in the PHP code though the LoginId value can be changed.

~ Answered on 2016-05-06 09:10:03


HI I got this from this site :

The web service has method Add which takes two params:

    $client = new SoapClient("http://localhost/csharp/web_service.asmx?wsdl");

     print_r( $client->Add(array("a" => "5", "b" =>"2")));

~ Answered on 2015-09-09 09:08:35

Most Viewed Questions: