I am trying to consume a web service that I created locally from an Android application. My problem is that in my Android app, at a certain point, I have to give an URL with parameters that looks like this : http://localhost:8080/CalculatorApp/CalculatorWSService/add?i=1&j=1
where CalculatorWS
is the web service I use, add
is the operation in it and i
and j
are parameters of add
operation. For now I am using a sample app Calculator (from NetBeans) for testing and I want to retrieve the correct URL to give to my web service client (Android app) so it can give me back an XML to parse.
I tried to use that URL mentioned above but it doesn't work.
Does anybody know what is the correct URL to put ?
Use this URL:
http://10.0.2.2:8080/CalculatorApp/CalculatorWSService/add?i=1&j=1
Since Android emulator run on Virtual Machine therefore we have to use this IP address instead of
localhost or 127.0.0.1
you need to set URL as 10.0.2.2:portNr
portNr = the given port by ASP.NET Development Server my current service is running on localhost:3229/Service.svc
so my url is 10.0.2.2:3229
i'd fixed my problem this way
i hope it helps...
sharktiger like you says on the comments, i'll paste here some code to help you to figure how to proced, this code try to connect to a web service and parse the InputStream retrieved, just like @Vikas Patidar and @MisterSquonk says, you must configure the url in the android code like them explain. So, i post my code
and example of call to HttpUtils...
and the method readHTTPContents from my class HTTPUtils
Hope this help you...
If you're using an emulator then read below paragraph taken from: Referring to localhost from the emulated environment