I m trying to teach myself SOAP, just to extend my skillset a bit, but I ve hit a wall and I was wondering if a kind developer out there can help?
I ve set up my server thus:
http://www.domain1.com/server.php
<?php
// Pull in the NuSOAP code
require_once( soap/nusoap.php );
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL( hellowsdl , urn:hellowsdl );
// Register the method to expose
$server->register( hello , // method name
array( name => xsd:string ), // input parameters
array( return => xsd:string ), // output parameters
urn:hellowsdl , // namespace
urn:hellowsdl#hello , // soapaction
rpc , // style
encoded , // use
Says hello to the caller // documentation
);
// Define the method as a PHP function
function hello($name) {
return Hello, . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ;
$server->service($HTTP_RAW_POST_DATA);
?>
And now I ve tried to set up a client on a seperate server:
http://www.domain2.com/client.php
<?php
// Pull in the NuSOAP code
require_once( soap/nusoap.php );
// Create the client instance
$client = new soapclient( http://domain.com/server.php?wsdl , true);
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo <h2>Constructor error</h2><pre> . $err . </pre> ;
// At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call( hello , array( name => Scott ));
// Check for a fault
if ($client->fault) {
echo <h2>Fault</h2><pre> ;
print_r($result);
echo </pre> ;
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo <h2>Error</h2><pre> . $err . </pre> ;
} else {
// Display the result
echo <h2>Result</h2><pre> ;
print_r($result);
echo </pre> ;
}
}
// Display the request and response
echo <h2>Request</h2> ;
echo <pre> . htmlspecialchars($client->request, ENT_QUOTES) . </pre> ;
echo <h2>Response</h2> ;
echo <pre> . htmlspecialchars($client->response, ENT_QUOTES) . </pre> ;
// Display the debug messages
echo <h2>Debug</h2> ;
echo <pre> . htmlspecialchars($client->debug_str, ENT_QUOTES) . </pre> ;
?>
But I can t get the fecking thing working. The server displays just fine - wdsl output the lot. But the client can t/won t connect and complete the transaction. I get this message:
Warning: SoapClient::SoapClient() expects parameter 2 to be array, boolean given in /home/public_html/slidebank_soap_client.php on line 5
Fatal error: Uncaught SoapFault exception: [Client] SoapClient::SoapClient() [<a href= soapclient.soapclient >soapclient.soapclient</a>]: Invalid parameters in /home/soap/slidebank_soap_client.php:5 Stack trace: #0 /home/soap/slidebank_soap_client.php(5): SoapClient->SoapClient( http://testing.... , true) #1 {main} thrown in /home/public_html/soap/slidebank_soap_client.php on line 5
And this is where I m stumped...
Any ideas?
H