client.php
$client = new SoapClient(“stockquote.wsdl”);
try {
print($client->getQuote(“ibm”));
}
catch(SoapFault $e) {
print "<pre>Exception:
";
print "Request :
“.htmlspecialchars($client->__getQuoteRequest()) .”
";
print "Response:
“.htmlspecialchars($client->__getQuoteResponse()).”
";
print “</pre>”;
die($e);
}
server.php
$quotes = array(
“ibm” => 98.42
);
function getQuote($symbol) {
global $quotes;
return $quotes[$symbol];
}
ini_set(“soap.wsdl_cache_enabled”, “0”); // disabling WSDL cache
$server = new SoapServer(“stockquote.wsdl”);
$server->addFunction(“getQuote”);
$server->handle();
stockcode.wsdl
<?xml version =‘1.0’ encoding =‘UTF-8’ ?>
<definitions name=‘StockQuote’
targetNamespace=‘http://example.org/StockQuote’
xmlns:tns=’ http://example.org/StockQuote ’
xmlns:soap=‘http://schemas.xmlsoap.org/wsdl/soap/’
xmlns:xsd=‘http://www.w3.org/2001/XMLSchema’
xmlns:soapenc=‘http://schemas.xmlsoap.org/soap/encoding/’
xmlns:wsdl=‘http://schemas.xmlsoap.org/wsdl/’
xmlns=‘http://schemas.xmlsoap.org/wsdl/’>
<message name=‘getQuoteRequest’>
<part name=‘symbol’ type=‘xsd:string’/>
</message>
<message name=‘getQuoteResponse’>
<part name=‘Result’ type=‘xsd:float’/>
</message>
<portType name=‘StockQuotePortType’>
<operation name=‘getQuote’>
<input message=‘tns:getQuoteRequest’/>
<output message=‘tns:getQuoteResponse’/>
</operation>
</portType>
<binding name=‘StockQuoteBinding’ type=‘tns:StockQuotePortType’>
<soap:binding style=‘rpc’
transport=‘http://schemas.xmlsoap.org/soap/http’/>
<operation name=‘getQuote’>
<soap:operation soapAction=‘urn:xmethods-delayed-quotes#getQuote’/>
<input>
<soap:body use=‘encoded’ namespace=‘urn:xmethods-delayed-quotes’
encodingStyle=‘http://schemas.xmlsoap.org/soap/encoding/’/>
</input>
<output>
<soap:body use=‘encoded’ namespace=‘urn:xmethods-delayed-quotes’
encodingStyle=‘http://schemas.xmlsoap.org/soap/encoding/’/>
</output>
</operation>
</binding>
<service name=‘StockQuoteService’>
<port name=‘StockQuotePort’ binding=‘StockQuoteBinding’>
<soap:address location=‘http://localhost/webservices/server.php’/>
</port>
</service>
</definitions>
I tried the above example, I got the error, as below
Exception:
Fatal error: Uncaught SoapFault exception: [Client] Function (“__getQuoteRequest”) is not a valid method for this service in C:\wamp\www\webservices\client.php:13
Stack trace:
#0 [internal function]: SoapClient->__call(‘__getQuoteReque…’, Array)
#1 C:\wamp\www\webservices\client.php(13): SoapClient->__getQuoteRequest()
#2 {main}
thrown in C:\wamp\www\webservices\client.php on line 13
Please tell me how to fix this error?
Regards,
Vanash