溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

PHP5SOAP調用原理有哪些以及怎么實現(xiàn)

發(fā)布時間:2021-10-18 17:42:25 來源:億速云 閱讀:86 作者:柒染 欄目:編程語言

本篇文章為大家展示了PHP5SOAP調用原理有哪些以及怎么實現(xiàn),內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

  SOAP(SimpleObjectAccessProtocol)簡單對象訪問協(xié)議是在分散或分布式的環(huán)境中交換信息的簡單的協(xié)議,是一個基于XML的協(xié)議。下面億速云小編來講解下PHP5SOAP調用原理有哪些?PHP5SOAP調用怎么實現(xiàn)?

  PHP5SOAP調用原理

  SOAP它包括四個部分:SOAP封裝(envelop),封裝定義了一個描述消息中的內容是什么,是誰發(fā)送的,誰應當接受并處理它以及如何處理它們的框架;SOAP編碼規(guī)則(encodingrules),用于表示應用程序需要使用的數(shù)據(jù)類型的實例;SOAPRPC表示(RPCrepresentation),表示遠程過程調用和應答的協(xié)定;SOAP綁定(binding),使用底層協(xié)議交換信息。

  WSDL(WebServiceDescriptionLanguage)就是描述XMLWeb服務的標準XML格式,WSDL由Ariba、Intel、IBM和微軟等開發(fā)商提出。它用一種和具體語言無關的抽象方式定義了給定Web服務收發(fā)的有關操作和消息。就其定義來說,你還不能把WSDL當作一種對象接口定義語言,例如,CORBA或COM等應用程序體系結構就會用到對象接口定義語言。WSDL保持協(xié)議中立,但它確實內建了綁定SOAP的支持,從而同SOAP建立了不可分割的聯(lián)系。所以,當我在該文中討論WSDL的時候,我會假定你把SOAP作為了你的通訊協(xié)議。

  SOAP和WSDL雖然是webservice的兩大標準,但是兩者并沒有必然的聯(lián)系,都可以獨立使用。它們之間的關系就類似HTTP和Html之間的關系。前者是一種協(xié)議,后者是對一個WebServer的描述。

  PHP5SOAP調用怎么實現(xiàn)

  PHP5下的配置

  在php的的配置文件php.ini中,找到

  extension=php_soap.dll

  然后將前面的;號去掉,然后重啟web服務

  查詢webservice方法與參數(shù)、數(shù)據(jù)類型

  某省電信公司的入單接口為http://***.******.com/services/AcceptedBusinesswsdl

  我們使用SoapClient的__geunctions()和__getTypes()方法查看該接口的方法,參數(shù)和數(shù)據(jù)類型

  只有__getFunctions中列出的接口才能被soap調用。

  在根目錄下創(chuàng)建代碼soap.php

  header("content-type:text/html;charset=utf-8");

  try{

  $client=newSoapClient("http://***.******.com/services/AcceptedBusinesswsdl");

  print_r($client->__getFunctions());

  print_r($client->__getTypes());

  }catch(SOAPFault$e){

  print$e;

  }

  >

  在瀏覽器運行:http://localhost/soap.php后,返回結果如下

  Array

  (

  [0]=>ArrayOf_xsd_anyTypeintroduceAcceptedBusiness(string$c3,string$c4,string$linkman,string$linknum,string$num,string$idcard,string$remark,string$address)

  [1]=>ArrayOf_xsd_anyTypeintroduceAcceptedBusinessByAiZhuangWei(string$subname,string$linkphone,string$idcard,string$address,string$businesstype,string$marketcode,string$surveycode,string$commanager,string$commanagerphone,string$bendiwang,string$fenju,string$zhiju,string$remark)

  [2]=>stringintroduceAcceptedBusinessByStandardInterface(string$xmlStr)

  [3]=>stringintroduceAcceptedBusinessByCallOut(string$xmlStr)

  [4]=>stringintroduceAcceptedBusinessByYddj(string$xmlParam)

  [5]=>ArrayOf_xsd_anyTypequeryAcceptedBusinessByAiZhuangWei(string$surveycode,string$starttime,string$endtime)

  [6]=>stringqueryCallOutOrderByConfig(string$xmlParam)

  )

  Array

  (

  [0]=>anyTypeArrayOf_xsd_anyType[]

  )

  其中有個方法introduceAcceptedBusinessByStandardInterface(string$xmlStr),將是開發(fā)文檔中提到的要使用的接口,參數(shù)為xml字符串

  另外有的接口中提到有SoapHeader認證,這就需要加入__setSoapHeaders方法,具體可查看http://php.net/manual/zh/soapclient.setsoapheaders.php

  提交入單

  這一步就是需要根據(jù)開發(fā)文檔拼接xml字符串,然后作為introduceAcceptedBusinessByStandardInterface的參數(shù)傳入

  創(chuàng)建acceptedbusiness.php,內容如下

  header("content-type:text/html;charset=utf-8");

  try{

  $client=newSoapClient('http://***.*******.com/services/AcceptedBusinesswsdl');

  $xml="

  **電信

  張三

  13412341234

  廣東深圳

  iPhone6

  1111111111111111111111111111111

  2111

  1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

  ";

  $return=$client->introduceAcceptedBusinessByStandardInterface($xml);

  print_r($return);

  }catch(SOAPFault$e){

  print_r('Exception:'.$e);

  }

  >

  在瀏覽器中執(zhí)行后,返回

  0

  入單成功!

  2014100905523549742

上述內容就是PHP5SOAP調用原理有哪些以及怎么實現(xiàn),你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI