PHP使用SOAP調(diào)用.net的WebService數(shù)據(jù)
更新時間:2013年11月12日 09:50:44 作者:
需要和一個.net系統(tǒng)進(jìn)行數(shù)據(jù)交換,對方提供了一個WebService接口,使用PHP如何調(diào)用這個數(shù)據(jù)呢,下面就看看使用SOAP調(diào)用的方法吧
這個與一般的PHP POST或GET傳值再查庫拿數(shù)據(jù)的思路有點不一樣,需要用到SOAP模塊,處理方法也很簡單,就是有一些需要注意的事情。
首先確認(rèn)你的PHP.ini開啟了.SOAP,就是 extension=php_soap.dll 這前面的分號去咯。
代碼很簡單:
<?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);
}
?>
需要注意的一點是,參數(shù)是數(shù)組外再包一層數(shù)組,就是 array( array() )
附SOAP接口的一些參數(shù):
以下是 SOAP 1.2 請求和響應(yīng)示例。所顯示的占位符需替換為實際值。
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/">
<soap:Body>
<GetArticle xmlns="http://tempuri.org/">
<param1>string</param1>
<param2>string</param2>
</GetArticle>
</soap:Body>
</soap:Envelope>
首先確認(rèn)你的PHP.ini開啟了.SOAP,就是 extension=php_soap.dll 這前面的分號去咯。
代碼很簡單:
復(fù)制代碼 代碼如下:
<?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);
}
?>
需要注意的一點是,參數(shù)是數(shù)組外再包一層數(shù)組,就是 array( array() )
附SOAP接口的一些參數(shù):
以下是 SOAP 1.2 請求和響應(yīng)示例。所顯示的占位符需替換為實際值。
復(fù)制代碼 代碼如下:
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/">
<soap:Body>
<GetArticle xmlns="http://tempuri.org/">
<param1>string</param1>
<param2>string</param2>
</GetArticle>
</soap:Body>
</soap:Envelope>
您可能感興趣的文章:
- PHP程序員簡單的開展服務(wù)治理架構(gòu)操作詳解(二)
- PHP程序員簡單的開展服務(wù)治理架構(gòu)操作詳解(一)
- PHP中soap用法示例【SoapServer服務(wù)端與SoapClient客戶端編寫】
- php中curl和soap方式請求服務(wù)超時問題的解決
- PHP使用NuSOAP調(diào)用Web服務(wù)的方法
- PHP中soap的用法實例
- PHP使用SOAP擴(kuò)展實現(xiàn)WebService的方法
- PHP Class SoapClient not found解決方法
- PHP實現(xiàn)Soap通訊的方法
- PHP使用SOAP調(diào)用API操作示例
- PHP程序員簡單的開展服務(wù)治理架構(gòu)操作詳解(三)
相關(guān)文章
Zend Framework框架實現(xiàn)類似Google搜索分頁效果
這篇文章主要介紹了Zend Framework框架實現(xiàn)類似Google搜索分頁效果,結(jié)合實例形式分析了Zend Framework框架實現(xiàn)分頁效果所涉及的基本查詢、判斷與分頁效果構(gòu)造相關(guān)操作技巧,需要的朋友可以參考下2016-11-11Laravel 創(chuàng)建指定表 migrate的例子
今天小編就為大家分享一篇Laravel 創(chuàng)建指定表 migrate的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10ThinkPHP中的系統(tǒng)常量和預(yù)定義常量集合
這篇文章主要介紹了ThinkPHP系統(tǒng)常量和預(yù)定義常量,需要的朋友可以參考下2014-07-07PHP使用星號替代用戶名手機(jī)和郵箱的實現(xiàn)代碼
這篇文章主要介紹了PHP使用星號替代用戶名手機(jī)和郵箱的實現(xiàn)代碼,需要的朋友可以參考下2018-02-02ThinkPHP模板判斷輸出Empty標(biāo)簽用法詳解
這篇文章主要介紹了ThinkPHP模板判斷輸出Empty標(biāo)簽用法,需要的朋友可以參考下2014-06-06使用 PHPMAILER 發(fā)送郵件實例應(yīng)用
以前的mail(),已經(jīng)不在流行,所以放上最近用的實例,留做回憶;需要的朋友可以參考下2012-11-11