php 如何利用 soap調用.Net的WebService asmx檔案

來源:互聯網
上載者:User

標籤:

原文:php 如何利用 soap調用.Net的WebService asmx檔案


最近,幫一個同行測試用.net寫的WebService介面,C#調用通過,現在需要測試一下php版本對它的調用,經過各種探索,

相關的PHP調用webservice的過程如下:

1.開啟php相關擴充:

   找到設定檔php.ini 檔案, 開啟以下擴充

  

extension = php_soap.dll
extension 
= php_curl.dll
extension 
= php_openssl.dll

 

 

2.php代碼如下:

 

<?php
header("content-type:text/html;charset=utf-8");
$client = new SoapClient(" http://192.168.3.178:8080/ChkWelePsw.asmx?WSDL");
$client->soap_defencoding = ‘utf-8‘;
$client->decode_utf8 = false;
$client->xml_encoding = ‘utf-8‘;
//本行測試不可行 $client = new SoapClient(" http://192.168.3.178:8080/chkwelepsw.asmx?WSDL/ChkWele?username=test3&psw=123");
//參數這樣傳遞 先封裝一下

$param = array(‘username‘=>‘test3‘,‘psw‘=>‘123‘);
//調用必須用__soapCall
$p = $client->__soapCall(‘ChkWele‘,array(‘parameters‘ => $param));//間接調用$p = $client->ChkWele($param);//直接調用print_r($p->ChkWeleResult);  //這裡先輸出一下變數$p,看看是什麼類型。
?>

 

 

注意,在php調用某個方法後,其soap對象,就會自動產生一個Result方法,以方便顯示調用結果,如上面的 被調用端的WebService的 “ChkWele”方法 ,

調用端就有相應的“ChkWeleResult”方法。

 

 

.NET部分 webservice要注意的地方

 

 

/*
 *    <system.web>在這個節點中加入如下內容
    <webServices>
     <protocols>
        <add name="HttpSoap"/>
        <add name="HttpPost"/>
        <add name="HttpGet"/>
        <add name="Documentation"/>
     </protocols>
    </webServices>  
 
*/
[WebMethod(Description 
= "This......", EnableSession = false)]
public string ChkWele(string username, string psw)
{
    
string ret = "";
    
return ret;
}

 

php 如何利用 soap調用.Net的WebService asmx檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.