簡體   English   中英

從SOAP客戶端請求到身份驗證的C#Web服務

[英]soapclient request from php to c# web service with authentication

我想使用php soap執行遠程功能。Web服務是使用c#.net創建的。必須進行身份驗證才能調用遠程功能。每次嘗試調用遠程功能時,我總是會得到未經授權的錯誤。通過使用這樣的wget獲取Web服務的內容

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

我得到了這個輸出:

    --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

任何意見?

提前致謝

我找到了解決此問題的替代方法

我准備並封裝了xml,並通過使用以信封為參數的curl發送請求。

$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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM