PHP SOAP Extension - A First SOAP Client (Page 2 of 8 )
To demonstrate how to make a simple SOAP Client, we’ll take the XMethods demo service, “Delayed Stock Quote”, as our target. Before we start to write any PHP code, we’ll need to gather some information about this particular service:
- The method name
- The endpoint URL where the service is running
- The SOAPAction header value for the method
- The namespace URI for the method
- Input and output parameter names and types
Happily, all this information is available on the XMethods web site at http://www.xmethods.com/ in the form of the service’s RPC profile:
| Method Name | getQuote |
| Endpoint URL | http://66.28.98.121:9090/soap |
| SOAPAction | urn:xmethods-delayed-quotes#getQuote |
| Method Namespace URI | urn:xmethods-delayed-quotes |
| Input Parameters | Symbol | String |
| Output Parameters | Result | float |
Example 1 (client1.php)
<?php
$client = new SoapClient(NULL,
array(
"location" => "<A href="http://66.28.98.121:9090/soap">http://66.28.98.121:9090/soap</A>",
"uri" => "urn:xmethods-delayed-quotes",
"style" => SOAP_RPC,
"use" => SOAP_ENCODED));
print($client->__call(
/* SOAP Method Name */
"getQuote",
/* Parameters */
array(
new SoapParam(
/* Parameter Value */
"ibm",
/* Parameter Name */
"symbol")),
/* Options */
array(
/* SOAP Method Namespace */
"uri" => "urn:xmethods-delayed-quotes",
/* SOAPAction HTTP Header for SOAP Method */
"soapaction" => "urn:xmethods-delayed-quotes#getQuote")). "n");
? >
As you can see, this simple task required a lot of work.
Fortunately, Web Services can describe themselves to the client using WSDL, and generally they achieve this successfully. The location of the WSDL document for the XMethods “Delayed Stock Quote” service is given on the information page for that
service at xmethods.com.
Next: Using WSDL >>
More Zend Articles
More By Zend