微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP使用SOAP调用.net的WebService数据

这个与一般的PHP POST或GET传值再查库拿数据的思路有点不一样,需要用到SOAP模块,处理方法也很简单,就是有一些需要注意的事情。
首先确认你的PHP.ini开启了.soAP,就是 extension=PHP_soap.dll 这前面的分号去咯。
代码很简单:
<div class="codetitle"><a style="CURSOR: pointer" data="6208" class="copybut" id="copybut6208" onclick="doCopy('code6208')"> 代码如下:

<div class="codebody" id="code6208">
<?PHP
$client = new SoapClient('http://www.aa.net/SearchService.asmx?WSDL');//这个SOAP地址要换成你自己的
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'utf-8';
$param = array('param1'=>'01','param2'=>'02');
//$param["param1"]="01";
//$param["param2"]="02";
//$result = $client->__soapCall("GetArticle",array( $param ));
$result = $client->__Call("GetArticle",array( $param ));
if (is_soap_fault($result))
{
trigger_error("SOAP Fault: (faultcode: {$result->faultcode},faultstring: {$result->faultstring})",E_USER_ERROR);
}
else
{
$data = $result->GetArticleResult;//这里返回的是类,必须使用->得到元素的值
print_r($data);
}
?>

需要注意的一点是,参数是数组外再包一层数组,就是 array( array() )
附SOAP接口的一些参数:
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。
<div class="codetitle"><a style="CURSOR: pointer" data="97922" class="copybut" id="copybut97922" onclick="doCopy('code97922')"> 代码如下:
<div class="codebody" id="code97922">
POST /SearchService.asmx HTTP/1.1
Host: 202.105.183.61
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetTrafficViolationInfo"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;

<GetArticle xmlns="http://tempuri.org/">
string
string

</soap:Body>
</soap:Envelope>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐