从今天开始,我要摘抄+个人理解放出php调用C# WebService JAVA调用C#WebService ……反正就是几个语言的杂交。要调用Web Service需要nusoap支持
5 }
在某php文件中如下写法:
<?php
require_once('nusoap.php');
/*架构师阿K的事。。*/
$client = new SoapClient('http://localhost/webservice1/service1.asmx?wsdl', true);
$str = $client->call('HelloWorld');
if(!$err = $client->getError())
{
echo "return:", $str['HelloWorldResult'];
}
else
{
echo "error:", $err;
}
?>
第一次搞这个php代码,只能意会了
这种方式不太好用,当使用PHPEclipse进行编译时,报告错误:
Debug Strict (PHP 5): /LocalizationTest/nusoap.php line 6496 - Assigning the return value of new by reference is deprecated
Compile Error: /LocalizationTest/nusoap.php line 7240 - Cannot redeclare class soapclient
自己发现可以通过改名字的方式修改nusoap.php剔除这个错误,这样总是不方便,后来发现php5本身就支持SOAP调用Web Service:
<?php
//get localization strings from C# webservice
$client = new SoapClient('http://localhost/webservice1/Localization.asmx?wsdl');
echo "Call web service method from C# WebService:\n";
$result = $client->GetLocalizationResource();
if(!is_soap_fault($result))
{
echo "return:\n", $result->GetLocalizationResourceResult;
}
else
{
echo "soap call fault";
}
?>
php soap调用的详细信息请参照这里