2011-02-09 45 views
1

我想通過使用php肥皂執行遠程功能。Web服務是通過使用c#.net.There必須進行身份驗證,以調用遠程功能。我總是會被授權錯誤,每當我試圖調用遠程function.However,當我通過使用wget這樣soapclient請求從PHP到c#web服務與身份驗證

wget -c --user=my_username --password=my_password http://path/to/wsdl 

獲得Web服務的內容和我得到這個輸出:

--2011-02-09 09:55:10-- http://path/to/wsdl 
Connecting to my_ip:80... connected. 
HTTP request sent, awaiting response... 401 Unauthorized 
Reusing existing connection to my_ip:80. 
HTTP request sent, awaiting response... 401 Unauthorized 
Reusing existing connection to my_ip:80. 
HTTP request sent, awaiting response... 200 OK 
Length: 3300 (3.2K) [text/html] 
Saving to: `my_webservice.asmx' 

100%[====================================================================================================================================================================================================>] 3,300  --.-K/s in 0.001s 

2011-02-09 09:55:11 (3.81 MB/s) - `my_webservice.asmx' saved [3300/3300] 

當我用肥皂序調用遠程功能如下:

$connSoap = new SoapClient($WebServiceUrl, array('login' => $username, 
               'password' => $password)); 
$requestOutput = $connSoap->GetVal (1, 1, 1); 

我得到這個錯誤:

SoapClient::SoapClient(http://path/to/wsdl): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized 

有何評論?

預先感謝

+0

根據需要使用的示例:用戶,狀陣列(「用戶」 => $用戶名, 「密碼」 => $密碼) – 2011-02-09 08:21:03

回答

0

我已經發現另一種方式做解決這個問題

我製備和包絡xml和通過使用具有包絡parameter.You可以參考下面的代碼捲曲發送請求;

$username = ""; 
$password = ""; 
$webServiceUrl = ""; 

$xml = '<?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> 
    <RemoteMethod xmlns="http://your.service.url/"> 
     <parameter_1>your_paramter_1</parameter_1> 
     <parameter_2>your_paramter_2</parameter_2> 
     ........ 
     <parameter_n>your_parameter_n</parameter_n> 
    </RemoteMethod> 
    </soap:Body> 
</soap:Envelope>'; 


$ch = fopen("envelope.xml", "w"); 
fwrite($ch, $xml); 

$cmd = 'curl -d @envelope.xml -H "Content-Type: text/xml;charset=UTF-8 " --user ' . $username . ':'.$password.' --ntlm ' . $webServiceUrl . ' > requestResult.xml'; 
shell_exec($cmd); 
fclose($ch);