Playing With NuSOAP
I spent two working days to find a reason why my PHP SOAP client doesn’t connect to the Perl SOAP server. As PHP SOAP implementation I use NuSOAP. I chose it because the SOAP client is needed for SugarCRM and NuSOAP is already included there.
I created client like that:
require_once('include/nusoap/nusoap.php');
$client = new soapclient('http://my.proxy.host:8086');
and then I called a simple method:
$result = $client->call('ping', array('pars' => 'Hi there!'), 'http://my.proxy.host/My/Class/Name');
I didn’t see any errors after that. I tried to switch on debug mode:
$soapclient->debug_flag = true;
. . .
echo 'Debug log: '.$soapclient->debug_str."\n";
and see request and responce:
echo 'Request: '.$soapclient->request."\n";
echo 'Response: '.$soapclient->response."\n";
Maybe I did somthing wrong but I couldn’t see anything! I captured the request and response using Ethereal. It showed me following response:
Application failed during request deserialization:
no element found at line 1, column 0, byte -1 at /usr/lib/perl5/site_perl/5.6.1/i386-linux/XML/Parser.pm line 193
I dived into Parser.pm and SOAP::Lite and found there was not XML content in the request (a Perl client works without any problems). I realy didn’t understand why it was not work correctly.
After some time I gave a guess what if I add some path in the proxy URL like that:
$client = new soapclient('http://my.proxy.host:8086/soap');
And oh miracle! It worked! My PHP client reseived a correct response! Unfortunatelly, I don’t know what the difference between proxy URL with some path and without for NuSOAP client. Maybe somebody can explain me?
Imho you should at least add trailing slash in the first URL so the string
client = new soapclient(‘http://my.proxy.host:8086’);
must looks like
client = new soapclient(‘http://my.proxy.host:8086/’);
That’s because nusoap uses parse_url() function to parse this string and in the first case this function doesn’t return ‘path’ value ’cause there’s no path. Later the POST request is constructed using the following code:
$this->outgoing_payload = “POST $this->path HTTP/1.0\r\n”;
so we don’t have any path from parse_url() we have invalid request:
POST HTTP/1.0
I think that is the problem. Try to end your endpoint string with only slash instead if the /soap string to see if I’m right in this case.
Thanks, you are absolutely right!
But probably this is a bug of nusoap. It’s easy to add ‘/’ by default if there is no path.