Jump to content

NuSoap + .Net web service problem.


mystery_man

Recommended Posts

Hi Guys

 

I need some urgent help on web services using NuSoap here from the southen tip of the 'dark continent', South africa. (And yes, pity me - yesterday I found a production web server of a certain ISP in SA running PHP 4.2.9!!  :wtf:)

 

I am busy with a website that needs to connect to a .net web service in order to validate some information against a MS SQL database, but that is completely transparent as the 2 web service methods does all the DB work.

 

Not having worked with web services before, I did some googling and stumbled upon NuSoap, which seems to be able to do the job. The fact that NuSoap is a standalone library you can just add onto your code is of importance, as I cannot tamper with the PHP extensions on the production server, and I don't think the server is even has the SOAP extension running.

 

Ok, I can connect to the web service, send the request and get the response, but it doesnt like what is sent, as what is being sent by my NuSoap Implementation is probably uncosure.

 

Here is the details of the one method exposed by the web service.

The wsdl stuff is here:

http://ww2.merseta.org.za/webservices/sampleservice1.asmx?WSDL

 



//The following is the sample SOAP 1.1 request for one of the methods

POST /webservices/sampleservice1.asmx HTTP/1.1
Host: ww2.merseta.org.za
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/OrgInfo"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <OrgInfo xmlns="http://tempuri.org/">
      <levyNo>string</levyNo>
    </OrgInfo>
  </soap:Body>
</soap:Envelope>


//The following is the sample SOAP 1.1 response

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <OrgInfoResponse xmlns="http://tempuri.org/">
      <OrgInfoResult>
        <xsd:schema>schema</xsd:schema>xml</OrgInfoResult>
    </OrgInfoResponse>
  </soap:Body>
</soap:Envelope>

 

Here is my php code using NuSoap:

 

//include the nuSoap lib
require_once('nuSoap/nusoap.php');

//construct the client object, using WSDL
$client = new nusoap_client("http://ww2.merseta.org.za/webservices/sampleservice1.asmx?WSDL", true);

//set encoding (it defaults to some ISO-... encoding)
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;

//if there is a problem, do the moaning...
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}

// This is some test data that should work fine.
$params = array(
    'levyNo' => "L630729640",
);

//cal the method 
$result = $client->call('OrgInfo', $params,'http://tempuri.org', "http://tempuri.org/OrgInfo");

//output of operation
if ($client->fault) {
echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2><pre>'; print_r($result); echo '</pre>';
} else {
$err = $client->getError();
if ($err) {
	echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
	echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';
}
}

//echo the output and debug stuff
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>'; 

 

ok, now this is what I am getting back from the server:

 

Error

XML error parsing SOAP payload on line 1: Empty document

Request

POST /webservices/sampleservice1.asmx HTTP/1.0
Host: ww2.merseta.org.za
User-Agent: NuSOAP/0.7.3 (1.114)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://tempuri.org/OrgInfo"
Content-Length: 433

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns8389="http://tempuri.org">
<SOAP-ENV:Body>
<OrgInfo xmlns="http://tempuri.org/">
<levyNo>L630729640</levyNo>
</OrgInfo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response

HTTP/1.1 200 OK
Connection: close
Date: Wed, 02 Sep 2009 09:14:31 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 386

Procedure or function 'RetrieveUserInfo' expects parameter '@levyNo', which was not supplied.

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
     <OrgInfoResponse xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>


 

I do not know how to get my request look more like the sample request that was provided, as I think this descrepancy is causing problems. There might be some dumb @ss Sh!t I in my code, I don't know anything about web services, please bear with me.

 

Any help, advice or suggestions will be very much appreciated.

 

Thank you.

Link to comment
Share on other sites

oh, And here is my PHP code I used:

 

$wsdl = "http://ww2.merseta.org.za/webservices/sampleservice1.asmx?WSDL";
$params = array('levyNo' => 'L630729640'); //test data
$namespace = "http://schemas.xmlsoap.org/soap/envelope/";
$soapAction = "http://tempuri.org/OrgInfo";
$methodname = "OrgInfo";


$client = new nusoap_client($wsdl);

//set encoding
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;

$result = $client->call($methodname, $params, $namespace, $soapAction);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.