2012-04-09 97 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标签