Consuming web service from PHP using NUSOAP

Hi all,

I developed a java web service(JAX-WS).
When I test the web service in browser, it is returning the values as required. (return value is a String array with 2 elements in it).

Then I try called this method(named getMoreFriends) of web service from php. It returns an error. Not sure what’s going on? :frowning:

Can anyone help me in this?

This is how my exact code:

<?php
require_once(‘nusoap.php’);

$zip = "95112";
$param = array('zipcode' =&gt; $zip);


$wsdl = "htp://localhost:8080/LocationWsApplication/moreFriendsService?WSDL";
// $mynamespace = "htp://phonedirlux.homeip.net/types"; no more need of this...
$client = new soapclient($wsdl, true);

$err = $client-&gt;getError();

if ($err) {
	echo 'Constructor error' . $err;
}

$response = $client-&gt;call('getMoreFriends', $param);

$err = $client-&gt;getError();

if ($err) {
	echo 'Error in fetching data' . $err;
}

foreach($response as $friend)
	echo $friend." ";

?>

Output: It is printing “Error in fetching data”…

Thanks,
Gaurang

The error is “…”?

Thanks 4 reply…

Is is not printing any error… I think, $err variable value is null…

So it displays just the error message text “Error in fetching data”…

One thing you would like to notice:
When I try ti print the values of the array elements, it shows “S:Client: Cannot find dispatch method for {}getMoreFriends”. Here getMoreFriends is the name of the method I am calling…

When debugging a nusoap server I use all these variables


    echo '<h2>Request</h2>';
    echo '<pre>' . htmlspecialchars($client -> request, ENT_QUOTES) . '</pre>';
    echo '<h2>Response</h2>';
    echo '<pre>' . htmlspecialchars($client -> response, ENT_QUOTES) . '</pre>';
    echo '<h2>Debug</h2>';
    echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
    echo '<h2>Error</h2>';
    echo '<pre>' . htmlspecialchars($client->getError(), ENT_QUOTES) . '</pre>';
    echo '<h2>Fault</h2>';
    echo '<pre>' . htmlspecialchars($client->fault, ENT_QUOTES) . '</pre>';

Debug has way to much information, but request and response usually have good debug info in them.

Hope this help :slight_smile:

This is the error I am getting:

S:Client: Cannot find dispatch method for {}getMoreFriends

There doesn’t really seem to be anything wrong with your client code, so is there a possibility that there is something wrong with the web service?
Have you tested the web service in any other way? Maybe with a java client?

I cannot say this is your solution, but my advice is to move to PHP5 and get away from nusoap, solved a lot of problems I was experiencing.

I am really confused. Working on this for past 3 days… still no clue… :mad:

I am putting my wsdl file over here… Can anyone help?

Here is wsdl file:


<definitions targetNamespace=“htp://calculator.me.org/” name=“moreFriendsService”>

<types>

<xsd:schema>
<xsd:import namespace=“htp://calculator.me.org/” schemaLocation=“htp://localhost:8080/LocationWsApplication/moreFriendsService?xsd=1”/>
</xsd:schema>
</types>

<message name=“getMoreFriends”>
<part name=“parameters” element=“tns:getMoreFriends”/>
</message>

<message name=“getMoreFriendsResponse”>
<part name=“parameters” element=“tns:getMoreFriendsResponse”/>
</message>

<portType name=“moreFriends”>

<operation name=“getMoreFriends”>
<input message=“tns:getMoreFriends”/>
<output message=“tns:getMoreFriendsResponse”/>
</operation>
</portType>

<binding name=“moreFriendsPortBinding” type=“tns:moreFriends”>
<soap:binding transport=“htp://schemas.xmlsoap.org/soap/htp” style=“document”/>

<operation name=“getMoreFriends”>
<soap:operation soapAction=“”/>

<input>
<soap:body use=“literal”/>
</input>

<output>
<soap:body use=“literal”/>
</output>
</operation>
</binding>

<service name=“moreFriendsService”>

<port name=“moreFriendsPort” binding=“tns:moreFriendsPortBinding”>
<soap:address location=“htp://localhost:8080/LocationWsApplication/moreFriendsService”/>
</port>
</service>
</definitions>

I suggest that you use PHP5’s native soapclient – NuSoap has weird bugs

I got it working finally… :cool:

The issue was I was not including namespace.
I copied the namespace from wsdl file… passed this namespace as third argument to call() method. working fine now… hats off to me…

code:
$result = $client->call(‘getMoreFriends’, array(‘zipCode’ => ‘95112’),‘htp://moreFriends/’);

here, htp://moreFriends/ is the namespace value I got from wsdl file.

Thanks all who replied to the post… :slight_smile:

Cheers,
Gaurang