0

i have created a Java Restful Web service. Now i want to access it in Android. There are different methods in Webservice. Web service is running on http://192.15.10.62:8080. how should i call a method named getGreetingMsg() in webservice which take a string argument and return a simple String message.

Web service Details

Project name RestFulWS

package Name rest.ws.server

class Name helloAndroid

Method Name getGreetingMsg(string argument)

any help will be appreciated.

4
  • this is not RESTful service ... Commented Feb 23, 2012 at 18:23
  • @Selvin why whats wrong with this Commented Feb 23, 2012 at 18:28
  • RESTful services dont have methods .... This services using http methods Commented Feb 23, 2012 at 18:31
  • here is my method @GET @Produces(MediaType.TEXT_PLAIN) public String getGreetingMsg(String mesg) { return "Hello User"; } Commented Feb 23, 2012 at 18:34

3 Answers 3

5

Simply with an HTTP client like AndroidHttpClient.

EDIT: RESTful web service is accessible through URL like:

http://yourserver/someservice/<categoryID>/<objectID>

So, you can test your webservice from a web browser like Internet Explorer or Mozilla Firefox.

Then, on Android, use HTTP Get request and the AndroidHttpClient.

Don't forget to set the INTERNET permission in your AndroidManifest.xml too

Sign up to request clarification or add additional context in comments.

4 Comments

can u tell me what is categoryID and ObjectID
It's just a general example. <categoryID> and <objectID> are variables. In your case, the URL could be something like: yourserver/helloAndroid/getGreetingMsg/<argument>
i am accessing a webservice by 10.99.17.103:8081/hello/sayPlainTextHello/my_string_argument HttpClient httpclient = new DefaultHttpClient(); --------- HttpGet httpget = new HttpGet(url); ---------- response = httpclient.execute(httpget); -------- but i am getting error at this Last line... Exception is Target Host must not be Null
Are you testing on a phone or emulator? Besides, have you tried to access this URL from the web browser?
1

It depend on the Web server you are using because each type of server will have its own URL to service hosted on it. If you are using JBOSS server then your URL looks like this IP:PORT/projectname/webservicename/method name

Comments

1

Sounds like you're not sure how to approach your own API. If your API supports GET, then open a web browser and try some GET commands. Once you have a GET statement working, work through this tutorial: http://sarangasl.blogspot.com/2011/06/android-login-screen-using-httpclient.html.

Once you're set with POST, turn off GET in your webserver.

Good luck!

db

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.