using NuSoap: consume a .NET web service in 10 min

25
Nov

The WSDL file

This is the URL for a WSDL file that hosted at a IIS server. http://www.webservicex.com/TranslateService.asmx?wsdl

So let's try to compose by our-self the content of the body of our SOAP message to query this web service, we will use NuSoap to achieve the job: we must use the targetnamespace this way, this .NET web service doesn't like the namespace prefix generated automatically by NuSoap
wsdl:definitions targetNamespace="http://www.webservicex.net"
nothing really difficult here, just follow the wsdl, or, use the tool TcpTunnelGui with a working client, or see the documentation generated by the .NET web service on-line
 
inputQuery we just have to specify the minOccurs="1" for our SOAP message to be accepted as a valid message by the web service. Add the other field, so the server will return some results...
 
SOAP Client is look like ..
<?php
require_once ('lib/nusoap.php');// include NuSOAP library
$soapaction = "http://www.webservicex.net/Translate"; // define the soapaction as found in the wsdl - yournamespase/webservicename
$wsdl="http://www.webservicex.com/TranslateService.asmx?wsdl";// Path to .asmx file
$namespace = "http://www.webservicex.net"; // name space found in WSDL - wsdl:definitions targetNamespace="http://www.webservicex.net"
$client = new soapclient($wsdl); // Crete a new SOAP client
$mysoapmsg = $client->serializeEnvelope ( '<Translate xmlns="http://www.webservicex.net"><LanguageMode>EnglishTOJapanese</LanguageMode><Text>Demo</Text></Translate>', '', array (), 'document', 'literal' );
$response = $client->send($mysoapmsg, $soapaction);
if ($client->fault) {// if some failure occure
print_r($response);

}
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>';
?>

 
 

Share/Save
9.41176
Average: 9.4 (17 votes)
Your rating: None

14 comments

4
Feb

Awesome, great tutorial .

Awesome, great tutorial . Thanks for sharing :o)

5
Feb

So let's try to compose by

So let's try to compose by our-self the content of the body of our SOAP message to query this web service, we will use NuSoap to achieve the job:

mpcoc

26
Feb

Very Useful information ,

Very Useful information , this is both
good reading for, have quite a few good key points, and I learn some
new stuff from it too, thanks for sharing your information.
regards,
handbags

16
Feb

Thanks for sharing this very

Thanks for sharing this very good and helpful topic.
cobro

16
Feb

Thanks for sharing this very

Thanks for sharing this very good and helpful topic.
cobro

17
Feb

Thanks for sharing! :o)

Thanks for sharing! :o)

7
Jan

Thanks for sharing! :o) <a

Thanks for sharing! :o) <a href="http://costcolocations.org">costco locations</a>

7
Jan

[url=http://costcolocations.o

[url=http://costcolocations.org]costco locations[/url]

17
Feb

Good enough to me, thanks for

Good enough to me, thanks for sharing!

18
Mar

It is not necessary to post

It is not necessary to post "Thank you" messages unless you have something else to contribute... not trying to be a dick.

Thanks for the post!

The example does not cover the scenario where you might need to pass parameters or headers to the webservice. In my situation, I am only using nusoap to make calls to a .NET server. So I modified the nusoap class (around line 7260 ish - in the 'call' method) to stop putting the prefix in there... as I would never need it. As a result, I can use a much shorter markup and utilize the built in validations and formatting that makes nusoap so great. You can even save this new class as something like nusoap.net.php and use it only when you are making calls to a .net server.

$wsdl = "http://yourdomain.com/WebServices/Service.asmx";
$params = array('param1' => 'value1');
$namespace = "http://tempuri.org/";
$soapAction = "http://tempuri.org/WebMethod";

$c = new soapclient($wsdl);
$response = $c->call('WebMethod', $params, $namespace, $soapAction);

Post new comment

 
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

Donate to Us


Activity Stream

Who's online

There are currently 0 users and 17 guests online.
Theme designed by Donny Carette - Powered by Drupal - copyright © 2010