chathuradd
chathuradd

Reputation: 165

how to call a C# .NET web service from a php client

I have a Hello World c# ASP .NET web service which is automatically generated by visual studio web service project. I want to call it from a php client. Can I know how to do it? Better if anyone can provide with small code example.. I dont have much experience in php and no in depth understanding of web services so finding difficult to do this..

Thanks

Upvotes: 0

Views: 3100

Answers (2)

Benny
Benny

Reputation: 3917

Since PHP is a dynamic language, its pretty straight forward. All you need is a library (SoapUI) and the WSDL. If you have the location (URL) of the web service add a ?WSDL to the end of the URL and you have the definition. Then its just calling the service from there.

<?php
require_once('libs/nusoap.php');
$wsdl="http://thedomain.com/theservice/endpoing.svc?wsdl";
$client=new soapclient($wsdl, 'wsdl');
$param=array('number1'=>'2', 'number2'=>'3');
echo $client->call('add', $param);
?>

You can find the library here: http://www.soapui.org/

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1503934

Assuming it's a SOAP web service, you should just be able to use the normal php SOAP library. Now SOAP portability isn't quite everything it's cracked up to be in my experience, so you may need to fiddle a bit (in particular, test things like how empty arrays work) but that should be a good starting point.

The docs I've linked to look pretty good, but if you search for "php SOAP tutorial" you get lots of hits which will take you through step-by-step.

Another option is nusoap. I can't comment on which implementation is better.

Upvotes: 1

Related Questions