Hi
I have created a soap server which resides in my local host folder but whenever I tried to connect to it it gave me and error the error is

Fatal error: Uncaught SoapFault exception: [HTTP] Unable to parse URL in D:\xampp\htdocs\Johansans Guides\client.php:11 Stack trace: #0 [internal function]: SoapClient->doRequest(‘soapCall(‘helloWorld’, Array) #2 {main} thrown in D:\xampp\htdocs\Johansans Guides\client.php on line 11

The server resides in my localhost folder and the server code is below

<?php

$server = new SoapServer(null, array('uri' => "urn://http:/www.wstutorial.com/"));
$server->addFunction("helloWorld");
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$server->handle();
}
else
{
echo "This SOAP Server Example can handle following functions:";
$functions = $server->getFunctions();
foreach($functions as $func)
{
echo $func ;
}
}
function helloWorld($buddy) {
return "Welcome to the world, " . $buddy . "!";
}
?>

whilst the client side code is

<?php

SoapClientExample.php

www.wstutorial.com – Web Services Tutorial

#
//ini_set('soap.wsdl_cache_enabled', 0);
//ini_set('default_socket_timeout' ,480);
$client = new SoapClient(null, array(
'location' => "localhost/Johansens Guides/soapserver1.php",
'uri' => "urn://www.wstutorial.com/",
'trace' => 1 ));

$return = $client->__soapCall("helloWorld",array("Tommy"));
echo $return;

?>

the file names of the soap and client are soapserver1.php and client.php respectively.

Any Ideas about why the coad breaks?

I will really appreciate your people help.

Thanks a lot

    I'm assuming you are supposed to communicate over http, so have you tried actually telling your soap client that?

      johanafm;10987449 wrote:

      I'm assuming you are supposed to communicate over http, so have you tried actually telling your soap client that?

      Hi,
      Dont have any ideas how the things roll when it comes to soap thing but all the code is there which I have pasted and the site from which I have copied this code didn't say that WSDL is necessary. that is why I have not scripted any of the wsdl for this soap application.

        wajidaktherabba;10987474 wrote:

        Dont have any ideas how the things roll when it comes to soap thing but all the code is there which I have pasted and the site from which I have copied this code didn't say that WSDL is necessary.

        Correct, using a WSDL document isn't necessary. However, if you don't know how "soap thing works", when they fail to work it's a good idea to read some documentation for NuSoap, wikipedia entry for SOAP, google for SOAP, see if you can find tutorials that explain how things work etc.

        What I meant when I said that I was assuming you wanted to communicate over http and that you should tell your soap client that you want to use http is that, unless the nusoap client defaults to http, there is no way for it to know what protocol to use, since there are others to choose from, such as HTTPS and SMTP.

        'location' => "localhost/Johansens Guides/soapserver1.php",
        

        I'm not saying this will not work, but I was wondering if you had tried specifying whatever communication protocol you want to use, such as

        'location' => "http://localhost/Johansens Guides/soapserver1.php",
        

        But, I decided to do some research and see what the nusoap client constructor expects, and hopefully being able to find out more information about the location element. So what I did was google nusoap and found NuSoap at sourcefourge. I started by downloading the Doc tarball from their web-browsable CVS repository, unpack it and discover that it didn't really work (broken links).
        Next up, I downloaded the NuSoap source code tarball, unpacked that and had a look in class.soapclient.php and discovered this at the very beginning of the class definition

        class nusoap_client extends nusoap_base  {
        	var $username = '';				// Username for HTTP authentication
        

        which means it was most likely developped for PHP 4, and while it may still work, I'd have expected it to be rewritten for PHP 5 this long after the death of PHP 4. And since you can get built in support for SOAP by compiling php with --enable-soap (iirc), I don't really see why you should use this at all. There is always a risk that something written for PHP 4 will someday break due to changes in new PHP versions.

        Next up, I discovered this

        	/**
        	* constructor
        	*
        	* @param    mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object)
        	* @param    mixed $wsdl optional, set to 'wsdl' or true if using WSDL
        	* ... [cut away]
        	*/
        	function nusoap_client($endpoint,$wsdl = false, /* cut way */){
        

        which means that you need to specify the endpoint as the first function argument (or the location of a WSDL document or a WSDL instance,) and the second argument which defaults to false should be set to 'wsdl' or true if the first argument is WSDL (I'm guessing this goes for both WSDL doc URL or a WSDL instance).

        However, your call to the constructor looks like this

        $client = new SoapClient(null, array('options));
        

        In other words, you are providing NuSoap with null as the endpoint, and resolving that as a url or WSDL instance will be impossible. I'm not certain how it would treat your second argument. It may decide that it's neither boolean true or the string 'wsdl' and decide that null is supposed to be the endpoint, or it may be treated as true and thus that the null value is your WSDL insance or WSDL doc url.

        Either way, it will not work.

        However, since the PHP doc for [man]SoapClient[/man]

        SoapClient::SoapClient ( mixed $wsdl [, array $options ] )

        matches your call to the constructor, I'm guessing your reading the wrong documentation or using the wrong code base. I recommend using the built in SoapClient over NuSoap.

          Write a Reply...