user1092042
user1092042

Reputation: 1295

Accesing soap service from android

This is a follow up on the question Android accesing soap service posted by me. After a lot of debugging and using wireshark i realised that this is what was being sent.

 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 

The error response

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

Details of what the site expects.

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

Upvotes: 0

Views: 1258

Answers (2)

Sujit Jadhav
Sujit Jadhav

Reputation: 1

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

add this to web.config file in system.web tag

Upvotes: 0

AYK
AYK

Reputation: 3322

The XML is case sensitive. Change

<password>

to

<Password>

everywhere applicable. See the tag definition below.

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

Edit : And yes, I assume you are properly closing the <UserName> tag and in the question is is a typo.

Edit Latest : After trying a sample through ASP.Net C#, I was able to get a response when sending following 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>

The response I get is :

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

Which i assume is a relevant response, when the user name and password are incorrect. Can you check by generating a similar request from Android ?

Edit : Added link on how to post XML from Android to a web service. Refer : Android, sending XML via HTTP POST (SOAP)

Upvotes: 1

Related Questions