2012-04-09 104 views
0

這是對我發佈的問題Android accesing soap service的跟進。經過大量的調試和使用wireshark,我意識到這是發送的內容。從android獲取肥皂服務

POST /GetGoldPrice.asmx HTTP/1.1 
user-agent: kSOAP/2.0 
soapaction: http://freewebservicesx.com/GetCurrentGoldPrice 
content-type: text/xml 
connection: close 
content-length: 475 
Host: www.freewebservicesx.com 

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body> 
<GetCurrentGoldPrice xmlns="http://www.freewebservicesx.com/" id="o0" c:root="1"> 
<UserName i:type="d:string">username</UserName> 
<Password i:type="d:string">111</Password></GetCurrentGoldPrice></v:Body></v:Envelope> 
HTTP/1.1 500 Internal Server Error 
Connection: close 
Date: Mon, 09 Apr 2012 04:38:50 GMT 
Server: Microsoft-IIS/6.0 
X-Powered-By: ASP.NET 
X-AspNet-Version: 2.0.50727 
Cache-Control: private 
Content-Type: text/xml; charset=utf-8 
Content-Length: 753 

錯誤響應的網站所期待的

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<soap:Body><soap:Fault><faultcode>soap:Server</faultcode> 
<faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; System.ArgumentNullException: Value cannot be null. 
Parameter name: password 
    at System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(String password, String passwordFormat) 
    at GetGoldPrice.GetCurrentGoldPrice(String UserName, String Password) 
    --- End of inner exception stack trace ---</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope> 

詳細信息。

http://www.freewebservicesx.com/GetGoldPrice.asmx?op=GetCurrentGoldPrice

回答

1

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> 
    <GetCurrentGoldPrice xmlns="http://freewebservicesx.com/"> 
     <UserName>string</UserName> 
     <Password>string</Password> 
    </GetCurrentGoldPrice> 
    </soap:Body> 
</soap:Envelope> 

編輯:是的,我認爲你是正確關閉<用戶名>標籤,並在問題是一個錯字。

編輯最新: 試圖通過ASP.Net C#的樣品後,我就能夠發送下面的XML時得到迴應。

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
    <GetCurrentGoldPrice xmlns="http://freewebservicesx.com/"> 
     <UserName>username</UserName> 
     <Password>password</Password> 
    </GetCurrentGoldPrice> 
    </soap:Body> 
</soap:Envelope> 

我得到的迴應是:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
    <GetCurrentGoldPriceResponse xmlns="http://freewebservicesx.com/"> 

     <GetCurrentGoldPriceResult> 
     <string>0</string> 
     <string>JAN 2, 2000 00:-00 PM EST</string> 
     <string>+0.0</string> 
     </GetCurrentGoldPriceResult> 
    </GetCurrentGoldPriceResponse> 
    </soap:Body> 
</soap:Envelope> 

我以爲是相關回應,在用戶名和密碼不正確。 您可以通過生成類似的Android請求來檢查嗎?

編輯:添加了如何將XML從Android發佈到Web服務的鏈接。 參見:Android, sending XML via HTTP POST (SOAP)

+0

添加到web.config文件已經更新的問題。同樣的錯誤仍然被拋出 – user1092042 2012-04-09 04:49:16

+1

我已經更新了我的回答與請求的格式,以使Web服務返回一個有效的XML響應。你可以檢查從Android產生相同的? – AYK 2012-04-09 05:04:39

+0

以上代碼由android生成併發布。看起來我的密碼在到達服務器時變爲空,但從我的機器發送得很好。任何想法,爲什麼在世界上這個SIS發生 – user1092042 2012-04-09 05:44:45

0
<webServices> 
    <protocols> 
    <add name="HttpGet"/> 
    <add name="HttpPost"/> 
    </protocols> 
</webServices> 

system.web標籤