php呼叫webservice的幾種方法
原文:php呼叫webservice的幾種方法 1.WSDL模式: extension = php_soap.dll extension = php_curl.dll extension = php_openssl.dll <?php header("content-type:text/html;charset=utf-8"); $client = new SoapClient("http://url/ooxx.asmx?wsdl"); $param = array(`引數`=>`值`,`引數`=>`值`); $p = $client->__soapCall(`呼叫方法名`,array(`parameters` => $param)); print_r($p->呼叫方法名Result); ?> $soap = new SoapClient("http://192.168.6.69:8899/Service1.asmx?wsdl"); $result2 = $soap->HelloWorld(array( `myName`=>`aaa`, `youName`=>`bbb` )); print_r($result2); 2.non-WSDL模式: 2.1使用SoapParam傳遞引數: $soap = new SoapClient(null,array(`location`=>`http://192.168.6.72:8036/Service1.asmx`,`uri`=>`http://tempuri.org/`)); $result2 = $soap->__soapCall("HelloWorld", array(new SoapParam("aaa", "myName"),new SoapParam("bbb", "youName")), //array(new SoapParam("aaa", "ns1:myName"),new SoapParam("bbb", "ns1:youName")), array(`soapaction`=>`http://tempuri.org/HelloWorld`)); print_r($result2); 2.2使用SoapVar傳遞引數 $ns = `http://tempuri.org/`; $soap = new SoapClient(null,array(`location`=>`http://192.168.6.72:8036/Service1.asmx`,`uri`=>$ns)); $result2 = $soap->__soapCall("HelloWorld", array(new SoapVar("AAA", XSD_STRING, null, $ns, "myName", $ns), new SoapVar("GBBB", XSD_STRING, null, $ns, "youName", $ns)), array(`soapaction`=>`http://tempuri.org/HelloWorld`)); print_r($result2); 3.新增安全Header $soap = new SoapClient(null,array(`location`=>`http://192.168.6.47/onvif/device_service`,`uri`=>`http://www.onvif.org/ver10/device/wsdl/`)); //ws $ns_wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";//WS-Security namespace $ns_wsu = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";//WS-Security namespace $userT = new SoapVar(`admin`, XSD_STRING, NULL, $ns_wsse, NULL, $ns_wsse); $passwT = new SoapVar(`NnYZe7oD81Kd8QRS4tUMze/2CUs=`, XSD_STRING, NULL, $ns_wsse, NULL, $ns_wsse); $createdT = new SoapVar(time(), XSD_DATETIME, NULL, $ns_wsu, NULL, $ns_wsu); class UsernameT1 { private $Username; //Name must be identical to corresponding XML tag in SOAP header private $Password; // Name must be identical to corresponding XML tag in SOAP header private $Created; function __construct($username, $password, $created) { $this->Username=$username; $this->Password=$password; $this->Created=$created; } } $tmp = new UsernameT1($userT, $passwT, $createdT); $uuT = new SoapVar($tmp, SOAP_ENC_OBJECT, NULL, $ns_wsse, `UsernameToken`, $ns_wsse); class UserNameT2 { private $UsernameToken; //Name must be identical to corresponding XML tag in SOAP header function __construct ($innerVal){ $this->UsernameToken = $innerVal; } } $tmp = new UsernameT2($uuT); $userToken = new SoapVar($tmp, SOAP_ENC_OBJECT, NULL, $ns_wsse, `UsernameToken`, $ns_wsse); $secHeaderValue=new SoapVar($userToken, SOAP_ENC_OBJECT, NULL, $ns_wsse, `Security`, $ns_wsse); $secHeader = new SoapHeader($ns_wsse, `Security`, $secHeaderValue); $result2 = $soap->__soapCall("GetDeviceInformation",array(),null,$secHeader); echo $result2;
相關文章
- 一種WebService的呼叫方式Web
- PHP呼叫Webservice例項PHPWeb
- js 呼叫 WebService 方法JSWeb
- php做的WebService用axis呼叫不到PHPWeb
- a 標籤中呼叫js的幾種方法JS
- PHP使用SOAP呼叫.net的WebService資料PHPWeb
- PHP呼叫java類的兩種方法(轉)PHPJava
- js呼叫後臺程式碼的幾種方法JS
- VB中呼叫WebService上的函式的方法Web函式
- PHP生成隨機密碼的幾種方法PHP隨機密碼
- PHP 清除字串中間的空格的幾種方法PHP字串
- [Java 基礎]--呼叫webservice介面的方法JavaWeb
- php抓取頁面的幾種方法詳解PHP
- php連線mysql資料庫的幾種方法PHPMySql資料庫
- php中計算時間差的幾種方法PHP
- php生成唯一id的幾種解決方法PHP
- java開發webservice幾種方式小結JavaWeb
- webservice介面呼叫Web
- PHP 判斷陣列是否為空的幾種方法PHP陣列
- PHP頁面跳轉幾種實現方法PHP
- 使用C#建立webservice及三種呼叫方式 (轉)C#Web
- 幾種函式呼叫方式函式
- Ajax呼叫WebService(一)Web
- C#呼叫webserviceC#Web
- webservice中呼叫structWebStruct
- PHP呼叫webservice遇到 Soap WSDL Error - "failed to load external entityPHPWebErrorAI
- [php]建立物件的幾種形式PHP物件
- java動態呼叫webserviceJavaWeb
- 新增webservice呼叫日誌Web
- Axis2呼叫WebServiceWeb
- webapi建立和呼叫WebServiceWebAPI
- php 非同步上傳圖片幾種方法總結PHP非同步
- xml操作的幾種方法XML
- 跨域的幾種方法跨域
- 說說Java非同步呼叫的幾種方式Java非同步
- WebService中使用自定義類的解決方法(5種)Web
- php中呼叫類的私有方法PHP
- 通過url獲取圖片尺寸的幾種方法:JS和phpJSPHP