PHP SOAP 教程

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   java   

一、SoapServer 伺服器

1、__construct
作用:建立 SoapServer 對象
用法:__construct ( mixed wsdl [, array options] )
參數:wsdl 檔案地址,options soap_version,encoding,actor,classmap
返回:對象

2、addFunction
作用:為用戶端匯出一個或多個函數
用法:addFunction ( mixed functions )
參數:functions 函數,一個或多個,全部 SOAP_FUNCTIONS_ALL
返回:無

3、getFunctions
作用:擷取全部函數
用法:getFunctions ()
參數:無
返回:函數數組

4、setClass
作用:匯出類中的全部函數
用法:setClass ( string class_name [, mixed args [, mixed ...]])
參數:class_name 類名 args 參數
返回:無

5、setPersistence
作用:允許儲存在PHP之間的會話請求資料
用法:setPersistence ( int mode )
參數:mode SOAP_PERSISTENCE_SESSION SOAP_PERSISTENCE_REQUEST
返回:無

6、fault
作用:允許儲存在PHP之間的會話請求資料
用法:fault ( string code, string string [, string actor [, mixeddetails [, string name]]] )
參數:code 錯誤碼 string 簡短錯誤資訊 actor 導致錯誤的字串 details 錯誤詳細資料
返回:無

7、handle ( [string soap_request] )
作用:處理一個SOAP請求,調用必要的功能,並發送回一個響應。
用法:handle ( [string soap_request] )
參數:soap_request 請求
返回:無

二、SoapClient 用戶端

1、__construct
作用:建立 SoapClient 對象
用法:__construct ( mixed wsdl [, array options] )
參數:wsdl 檔案地址 或 null,
options
a、soap_version soap版本,encoding 編碼,compression 壓縮,classmap
b、http身分識別驗證 :login , password
c、代理服務:proxy_host, proxy_port, proxy_login and proxy_password
d、認證驗證:local_cert , passphrase
e、wsdl 為null 時:location , uri
返回:對象

2、__call
作用:調用函數
用法:__call ( string function_name, array arguments [, array options[, array input_headers [, array output_headers]]] )
參數:function_name,arguments
返回:無

3、__doRequest
作用:在執行HTTP請求
用法:__doRequest ( string request, string location, string action,int version [, int one_way] )
參數:request XML的SOAP請求 location 請求地址 action ,version
返回:字串

4、__getFunctions
作用:擷取全部方法
用法:__getFunctions( )
參數:無
返回:函數數組

5、__getFunctions
作用:擷取全部方法
用法:__getFunctions( )
參數:無
返回:函數數組

6、__setCookie
作用:設定cookie
用法:__setCookie ( string name [, string value] )
參數:name cookie名稱 value cookie值
返回:無

7、__getLastRequest
作用:擷取最後的請求
用法:__getLastRequest ()
參數:無
返回:最後的請求

8、__getLastRequestHeaders
作用:擷取最後的要求標頭部資訊
用法:__getLastRequestHeaders ()
參數:無
返回:最後的要求標頭部資訊

9、__getLastResponse
作用:擷取最後的回應
用法:__getLastRequest ()
參數:無
返回:最後的請求回應

10、__getLastResponseHeaders
作用:擷取最後的回應頭部資訊
用法:__getLastResponseHeaders ()
參數:無
返回:最後的回應頭部資訊

三、SoapVar 參數

1、__construct
作用:建立 SoapVar 對象
用法:__construct ( mixed data, int encoding [, string type_name [,string type_namespace [, string node_name [, stringnode_namespace]]]] )
參數:data 資料,encoding 編碼
返回:參數對象

四、SoapParam 參數

1、__construct
作用:建立 SoapParam 對象
用法:__construct ( mixed data, string name )
參數:data 傳遞的變數,name 變數的值
返回:參數對象

__construct ( string namespace, string name [, mixed data [,bool mustUnderstand [, mixed actor]]] )

五、SoapHeader 頭部

1、__construct
作用:建立 SoapHeade 對象
用法:__construct ( string namespace, string name [, mixed data [,bool mustUnderstand [, mixed actor]]] )
參數: namespace 命名空間 name SOAP 頭標籤名稱 ,data 頭部內容
返回:對象

六、SoapFault 頭部

1、__construct
作用:建立 SoapFault 對象
用法:__construct ( string faultcode, string faultstring [, stringfaultactor [, mixed detail [, string faultname [, SoapHeaderheaderfault]]]] )
參數: faultcode 錯誤碼,faultstring 錯誤資訊 ,faultactor 導致錯誤字串,detail錯誤詳情
返回:對象

七、例子

1、定義一個類

<?php    class  Culculator      {          public   function  sum( $x , $y )           {               return   $x  +  $y ;           }      }      class Culculator      {          public function sum($x,$y)           {               return $x + $y;           }      }  ?>

2、使用Zend Studio產生wsdl檔案;

3、SOAP 伺服器端 (server.php)

<?php    require   ‘./Culculator.php‘ ;            $server  = newSoapServer( ‘./wps.wsdl‘ );      $server ->setClass( ‘Culculator‘ );      $server ->handle();       require ‘./Culculator.php‘;            $server = newSoapServer(‘./wps.wsdl‘);      $server->setClass(‘Culculator‘);      $server->handle();?>

3、SOAP 用戶端(client.php)

<?php     $soap  = newSoapClient( ‘./wps.wsdl‘ );      echo   $soap ->sum(1,2);      //運行輸出 3  ?>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.