How to easily use a web service from PHP

Is there any tool for PHP that can be used to generate code to use a web service based on its WSDL ? Something like clicking Add Web Link in Visual Studio or the Eclipse plugin that does the same for Java.

+52
wsdl php visual-studio web-services
Aug 07 '08 at 5:48
source share
7 answers

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

+19
Aug 15 '08 at 18:36
source share

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

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

and $ client is now an object that has class methods defined in some.wsdl. Therefore, if the getTime method was found in the WSDL, you simply call:

 $result = $client->getTime(); 

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

+85
Aug 23 '08 at 18:54
source share

I have used NuSOAP in the past. I liked it because it is just a bunch of PHP files that you can include. You cannot install and set configuration parameters on the web server. It also supports WSDL, which is a bonus.

+9
Aug 13 '08 at 13:54
source share

Well, these features are specific to the tool that you use to develop in these languages.

You would not have these tools if (for example) you used notepad to write code. So, maybe you should ask a question for the tool you are using.

For PHP: http://webservices.xml.com/pub/a/ws/2004/03/24/phpws.html

+2
Aug 07 '08 at 7:17
source share
+2
Jul 26 '11 at 9:17
source share

HI I got this from this site: http://forums.asp.net/t/887892.aspx?Consume+an+ASP+NET+Web+Service+with+PHP

The web service has an Add method that takes two parameters:

 <?php $client = new SoapClient("http://localhost/csharp/web_service.asmx?wsdl"); print_r( $client->Add(array("a" => "5", "b" =>"2"))); ?> 
+1
Sep 09 '15 at 9:08
source share

Say that you have been given the following:

 <x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://thesite.com/"> <x:Header/> <x:Body> <int:authenticateLogin> <int:LoginId>12345</int:LoginId> </int:authenticateLogin> </x:Body> </x:Envelope> 

and

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <authenticateLoginResponse xmlns="http://thesite.com/"> <authenticateLoginResult> <RequestStatus>true</RequestStatus> <UserName>003p0000006XKX3AAO</UserName> <BearerToken>Abcdef1234567890</BearerToken> </authenticateLoginResult> </authenticateLoginResponse> </s:Body> </s:Envelope> 

Let's say that access to http://thesite.com/ indicates that the WSDL address is: http://thesite.com/PortalIntegratorService.svc?wsdl

 $client = new SoapClient('http://thesite.com/PortalIntegratorService.svc?wsdl'); $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 elements specified in XML are used in the PHP code, although the LoginId value can be changed.

+1
May 6 '16 at 9:10
source share



All Articles