0

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

Community
  • 1
  • 1
user1092042
  • 1,297
  • 5
  • 24
  • 44

2 Answers2

1

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)

Community
  • 1
  • 1
AYK
  • 3,312
  • 1
  • 17
  • 30
  • Have updated the question. The same error is still being thrown – user1092042 Apr 09 '12 at 04:49
  • 1
    I have updated my answer with the request format, to which the web service returns a valid XML response. Can you check generating the same from Android ? – AYK Apr 09 '12 at 05:04
  • The above code was generated by android and posted. Lookls like my password is becoming null when it reaches the server but is sending fine from my machine. Any idea why in the world this sis happening – user1092042 Apr 09 '12 at 05:44
  • I strongly feel that the server is not able to identify your tag because of XML not being in proper format. Can you just try to post the XML I gave in my answer, maybe without using your KSoap implementation. Just try, if this works, your KSoap is not generating a valid XML. BTW, this is just a wild guess. – AYK Apr 09 '12 at 05:49
  • Does the passwords need to be hashed – user1092042 Apr 09 '12 at 12:24
  • I cannot say that the password needs to be hashed, you will have to check when you successfully post the XML. I have updated my answer and added a link on how to post XML to a web service in Android. Hope it will be clear now. – AYK Apr 09 '12 at 12:29
0
<webServices>
  <protocols>
    <add name="HttpGet"/>
    <add name="HttpPost"/>
  </protocols>
</webServices>

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

Daniel Kutik
  • 6,997
  • 2
  • 27
  • 34