...

View Full Version : Consuming a .NET webservice



rrhandle
01-01-2004, 08:57 PM
I am a ASP developer who has a client wishing to consume my webservice. The client's site is coded in PHP, and running on a Unix server. After days of trying to learn PHP, XML_RPC, NuSOAP, and PEAR, I admit I am lost.

I create a simple test webservice hoping one of you PHP gurus could show me how to consume it.

The webserviec is located at:
http://www.astro-matchmaker.com/aspnet_sample/Simple_Test.asmx

NameSpace is: ns.www.astromatchmaker.com
Class name is: Simple_test
Method name is: test
The method takes two parameters: strFirstName, strLastName
The method returns a string.

Any help would be greatly appreicated!

Thanks, Rob

firepages
01-02-2004, 04:50 AM
HI , never touched a .NET web-service , but firstly nusoap is probably the best option as it has no dependencies (like PEAR::SOAP) nor requires any server extensions..

now this might be expected to work or return something , but I got no response from your server , unless of course you are only allowing local requests ...



<?php
require_once('nusoap.php');

$param = array('strFirstName'=>'rodney','strLastName'=>'redhat');
$serverpath ='www.astro-matchmaker.com/aspnet_sample/Simple_Test.asmx';
$namespace="ns.www.astromatchmaker.com/test";

$client = new soapclient( $serverpath );
$client->debug_flag=true;

$yaks= $client->call( 'test' , $param , $namespace ) ;

echo $client->error_str;
print_r($yaks);

unset($client);
?>

rrhandle
01-02-2004, 05:15 AM
Thanks for the response. We are bothing thinking along the same lines. Below you will see the code I cobbled together. It contacts the service, but my $param array sends nothing; therefore, I don't receive the right response which should contain the two variables I am passing, namely, Frist name and Last Name.

<?php
require_once('NuSOAP/nusoap-0.6.1/nusoap.php');
$client = new soapclient('http://www.astro-matchmaker.com/aspnet_sample/Simple_Test.asmx?wsdl', 'wsdl');

$param = array('strFirstName'=>'dory','strLastName'=>'Mory');

$namespace = "urn:ns_www.astromatchmaker.com";
$response = $client->call("test", $param, $namespace);

// Display the request and response
echo '<h2>Request</h2>';
echo '' . htmlspecialchars($client->request, ENT_QUOTES) . '';
echo '<h2>Response</h2>';
echo '' . htmlspecialchars($client->response, ENT_QUOTES) . '';



// if a fault occurred, output error info
if (isset($fault)) {
print "Error: ". $fault;
}
else {
print "no errors";
}

print "<BR>";
print 'The response is:<pre>';
print "</pre><br>";
print(htmlentities($response));


// kill object
unset($client);




?>

firepages
01-02-2004, 06:39 AM
ok , well this works , whether the fact that nusoap does not format the request correctly is due to a nusoap internal issue or your wsdl I could not say (perhaps fire them off a mail ?) , but sending the body of the request itself seems to work if a little more verbose !



<?php
require_once('nusoap.php') ;
$client = new soapclient('http://www.astro-matchmaker.com/aspnet_sample/Simple_Test.asmx?wsdl' , true ) ;
$msg = '
<test xmlns="ns.www.astromatchmaker.com">
<strFirstName>Rodney</strFirstName>
<strLastName>Redhat</strLastName>
</test>
';
$response = $client->call( "test" , array($msg) ) ;

// Display the request and response
echo '<h2>Request</h2>';
echo '' . htmlspecialchars($client->request, ENT_QUOTES) . '';
echo '<h2>Response</h2>';
echo '' . htmlspecialchars($client->response, ENT_QUOTES) . '';

if ( isset( $fault ) ) {
print "Error: ". $fault;
}else{
print "no errors";
}
echo "<br /> <br />The response is " . $response ;
unset($client);
?>

firepages
01-02-2004, 06:43 AM
errr sorry about the urls getting parsed by the BB , I told it not to but I got ignored ;)

so that should be
<test xmlns="ns.www.astromatchmaker.com">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum