-1

I'm a learner of both java and android programming. I made a web service of hello world. Created a class called HelloWorld. There is only one method in it like

sayHello(){
System.out.println("hello world")
}

Now how should I write a android main activity to invoke this method using http request. what are the prerequisites to use http request. What are the libraries to import. Should I download any library from any where? I googled for it. Many irrelevant results are coming. I'm not able to comprehend from them.So seeking help here which seemed to be the only option.

Kind answer is appreciated.

Krishna
  • 601
  • 2
  • 9
  • 32
  • 1
    I don't think you can make a webservice run in an android application. they usually run on servers, unless you can find a webserver that runs on android. – toskv Sep 01 '15 at 19:24
  • 1
    This might be helpful http://stackoverflow.com/questions/6047194/how-to-call-restful-web-service-from-android – Asif Iqbal Sep 01 '15 at 19:25
  • I downloaded apache tomcat and installed in my windows pc. Used Eclipse to make the service(Actually I dont know how to make a service also, but fortunately found an article which taught how to write a web service in eclipse step by step) – Krishna Sep 01 '15 at 19:27
  • 1
    Oh, I read that wrong. I thought you wanted to host the webservice on your android device. :) If you want to call a webservice Asif's link might indeed help. :) – toskv Sep 01 '15 at 19:28
  • @AsifIqbal thank you for a reference. But I dont know any kind of REST or SOAP. I didn't even use jersy frame work( don't know what does that mean) will the answer applicable to my question? – Krishna Sep 01 '15 at 19:32

1 Answers1

1

The Android platform comes with everything you need to make HTTP requests. You should take a look at the URLHttpConnection. Bear in mind, that making an HTTP request is a bit harder then just using this class. You should think about doing it on a worker thread, so you don't block the UI. You should also think about the data transfer protocol you are going to use for your client - server communication and how to process the received responses.

I think this can get you started: http://developer.android.com/training/basics/network-ops/connecting.html

When you feel more comfortable with the concept, you can try and use a library for your HTTP request. Here is a useful link: https://developer.android.com/training/volley/index.html

Only one thing - seems like your web service is not sending any data back to clients, it's just printing to the server standard output, so it is unlikely you see any information sent to your Android app.

Danail Alexiev
  • 7,624
  • 3
  • 20
  • 28
  • thanks for the resources. I need them badly. Here I intentionally made that kind of service which will not give data back to me, so that I can first understand what is a web service , what are endpoints. Otherwise I think I have to deal with those xml stuff for transfering data. Right?(If so, I dont want to make my learning harder.) If you can suggest me any kind of resource so that I can get complete info on how to use the http, I'll be so thankful to you. – Krishna Sep 01 '15 at 19:39
  • JSON is a simpler, modern alternative to XML. To get to know, google some info about it. There are APIs supporting writing/parsing JSON on both the Java platform and the Android platform. I recommend it over XML. Try to follow the example from the first link, transferring some small JSON object. When you get this right, you can start doing more complex stuff. – Danail Alexiev Sep 01 '15 at 19:42