您的位置:首页 > 编程语言 > PHP开发

php 如何利用 soap调用.Net的WebService asmx文件

2016-07-04 17:02 771 查看
原文:php 如何利用 soap调用.Net的WebService asmx文件

最近,帮一个同行测试用.net写的WebService接口,C#调用通过,现在需要测试一下php版本对它的调用,经过各种探索,
相关的PHP调用webservice的过程如下:

1.打开php相关扩展:

找到配置文件php.ini 文件, 打开以下扩展

extension = php_soap.dll
extension = php_curl.dll
extension = php_openssl.dll

2.php代码如下:

<?php
header("content-type:text/html;charset=utf-8");
$client = new SoapClient(" http://192.168.3.178:8080/ChkWelePsw.asmx?WSDL");
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'utf-8';

//本行测试不可行 $client = new SoapClient(" http://192.168.3.178:8080/chkwelepsw.asmx?WSDL/ChkWele?username=test3&psw=123"); //参数这样传递 先包装一下
$param = array('username'=>'test3','psw'=>'123');
//调用必须用__soapCall
$p = $client->__soapCall('ChkWele',array('parameters' => $param));//间接调用
$p = $client->ChkWele($param);//直接调用
print_r($p->ChkWeleResult); //这里先输出一下变量$p,看看是什么类型。
?>

注意,在php调用某个方法后,其soap对象,就会自动产生一个Result方法,以方便显示调用结果,如上面的 被调用端的WebService的 “ChkWele”方法 ,

调用端就有相应的“ChkWeleResult”方法。

.NET部分 webservice要注意的地方

/*
* <system.web>在这个节点中加入如下内容
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>
*/
[WebMethod(Description = "This......", EnableSession = false)]
public string ChkWele(string username, string psw)
{
string ret = "";
return ret;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: