14.3.1. ProblemYou want to send a SOAP request to a service that does not expose a WSDL file, so you must specify the information usually provided there yourself. 14.3.2. SolutionPass a null value for the location of the WSDL, and the main service settings, such as location and namespace URI, in the options array: <?php $opts = array('location' => 'http://64.124.140.30:9090/soap', 'uri' => 'urn:xmethods-delayed-quotes', $client = new SOAPClient(null, $opts); ?> Make requests using the __soapCall( ) method, passing the method name as the first parameter, and an array of method arguments as the second: $quote = $client->__soapCall('getQuote', array('EBAY')); // eBay, Inc. print $quote; 31.49 14.3.3. DiscussionSince you're not using WSDL, pass null as the first argument to SOAPClient. This tells the SOAP extension that you're passing the details about the web service in the second parameter of options. This information is stored as an array. At a minimum, you must provide two entries: the URL where the SOAP server is located and the namespace URI that identifies the service. For example: <?php $opts = array('location' => 'http://64.124.140.30:9090/soap', 'uri' => 'urn:xmethods-delayed-quotes', $client = new SOAPClient(null, $opts); ?> The server's URL is the location element; here, the server is at http://64.124.140.30:9090/soap. The server's namespace is set using the uri element. This is urn:xmethods-delayed-quotes. Now you have a SOAP client, but with a non-WSDL-based client, you can't directly invoke SOAP methods on the $client object. Instead, you reference the __soapCall( ) method, passing the method name as your first argument and an array of parameters as the second: <?php $quote = $client->__soapCall('getQuote', array('EBAY')); // eBay, Inc. print $quote; ?> 31.49 Since the SOAP client no longer knows how many parameters to expect, you must bundle your parameters to __soapCall( ) inside of an array. Therefore, the stock quote is now passed as array('EBAY') instead of 'EBAY'. This code is more complex than the WSDL solution, and it even takes advantage of some default SOAP settings assumed by SOAPClient. This interface for calling SOAP methods is also less elegant. However, this is the only way to pass or read additional information, such as SOAP headers. 14.3.4. See Also14.2 for making SOAP requests with WSDL; Recipe 15.2 for more on SOAP servers; the ext/soap documentation at http://www.php.net/soap; Programming Web Services with SOAP, by Doug Tidwell, James Snell, and Pavel Kulchenko (O'Reilly). |