Skip to content Skip to sidebar Skip to footer

Interacting With Web Services And Android

I want to make a request to a web services http://www.w3schools.com/webservices/tempconvert.asmx and I cannot get a OK respond and got 400 bad request instead. Here is my AsyncTas

Solution 1:

EDIT: I just saw your content-type header, have you tried "application/soap+xml"? Also, SOAP required POST I believe, GET will not work, so you're right to do POST.

EDIT2: That client class your using isn't going to work. You need to send a XML in the body of your POST request, wrapped in a SOAP XML wrapper. The XML needs to follow the structure of the WSDL for your endpoint. I would recommend using SOAP UI (link below) to figure out what the XML should look like. If you wanted to get fancy, you should create a class that will serialize to look exactly like the request the SOAP UI creates.

For SOAP services you can almost always access the WSDL by adding ?WSDL to the endpoint url: http://www.w3schools.com/webservices/tempconvert.asmx?wsdl

If that doesn't work...

How to troubleshoot web services:

  1. Download and install SoapUi and get your SOAP request working by importing your WSDL and filling in required inputs
  2. Once your request is working install fiddler or some other proxy
  3. Change the URL of your request in SoapUI to localhost:8888 or whatever the name of your machine is and the port where your proxy is running (fiddler runs on 8888 by default).
  4. Make the same working request from SoapUI but to the new URL (localhost:8888 or whatever), the request will fail, but fiddler will have captured your request
  5. Now in your android code, change the URL of the SOAP request to localhost:8888 and make the request, this will also fail but fiddler will have captured your request
  6. Look at the two requests and compare them. Start by looking at the headers and then the SOAP wrapper/xml.

I've done exactly this a million times, it's a guaranteed method to find the difference between two requests. Good luck!

Solution 2:

Are you sure that a POST is correct. When I do a GET for that URL in Chrome I get 200 OK. Maybe you should try changing to the following?

client1.Execute(RequestMethod.GET);

Post a Comment for "Interacting With Web Services And Android"