這是我第一次與Web服務/ SOAP .NET Web服務......我一直在試圖消耗使用PHP,但無濟於事的.NET Web服務。我已經搜索並閱讀了谷歌拋出所有與此相關的所有頁面,但我仍然迷失。消費使用PHP
的東西是SOAP服務我試圖調用具有授權頭,我無法想出一個辦法來驗證我的要求。
我已經嘗試了PHP的SoapClient的和的NuSOAP,但都沒有可用的示例代碼,這將有助於。所以任何幫助都會很棒。
以下是一個示例SOAP 1.1請求和響應。
POST /OxiWalletService/Service.asmx HTTP/1.1
Host: 172.160.0.49
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/WS_GetData"
<?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:Header>
<AuthHeader xmlns="http://tempuri.org/">
<UserName>string</UserName>
<Password>string</Password>
</AuthHeader>
</soap:Header>
<soap:Body>
<WS_GetData xmlns="http://tempuri.org/">
<xmlString>string</xmlString>
</WS_GetData>
</soap:Body>
</soap:Envelope>
響應
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<WS_GetDataResponse xmlns="http://tempuri.org/">
<WS_GetDataResult>string</WS_GetDataResult>
</WS_GetDataResponse>
</soap:Body>
</soap:Envelope>
任何人能請給我如何消費這樣的服務的示例代碼。
非常感謝提前!
這是我已經用於調用web服務
<?php
$soap_client = new SoapClient("http://172.160.0.49/OxiWalletService/Service.asmx?WSDL");
$Uid='oxigen';
$Pwd='oxigen';
$ns = "http://tempuri.org/";
//Body of the Soap Header.
$headerbody = array('UserName' => $Uid,
'Password' => $Pwd
);
//Create Soap Header.
$header = new SOAPHeader($ns, 'AuthHeader', $headerbody);
//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header);
$par="<Wallet><SPName>AuthenticateMerchantWebVending</SPName><Parameters><Parameter><Name>@Account</Name><Size>50</Size><Value>1135600016</Value><Type>varchar</Type></Parameter><Parameter><Name>@Password</Name><Size>20</Size><Value>0OgknrdonyM=</Value><Type>varchar</Type></Parameter></Parameters><ParameterCount>2</ParameterCount><DataBase>1</DataBase></Wallet>";
$param=array('xmlString'=>$par);
$result=$soap_client->__SoapCall('WS_GetData',$param);
print_r ($result);
?>
代碼和我得到以下作爲輸出:
stdClass的對象([WS_GetDataResult] => 2Unknown錯誤)
想法??
因此,原來你已經通過第二個參數與參數數組
意義的關鍵這一
$result=$soap_client->__SoapCall('WS_GetData',$param);
應該
$result=$soap_client->__SoapCall('WS_GetData',array('parameters'=>$param));
這就是現在的工作。
http://stackoverflow.com/questions/1581169/invoking-net-web-service-with-php – Arfeen 2012-01-30 10:21:33
還要檢查HTTP:// www.scottnichol.com/nusoapprogwsdl.htm教程 – Arfeen 2012-01-30 10:23:41