Doubts in the web service

Asked

Viewed 1,080 times

0

personal found the following webservice tutorial: https://www.youtube.com/watch?v=0J87qN3B-dI

seeing the tutorial I was a little confused about.

1- the web service must be made the part of the android application?

for example I create a web service put this web service on the server and then create the application by android studio and make the connection to the web service?

2 - I must create web service by eclipse?

3 - in this tutorial it uses mysql, but I need to use Firebird, in this case I must put the.fdb database somewhere in Tomcat or the database will be accessed in the same way by the same localhost in the tutorial?

4 - I have a desktop system in Delphi, if I do web service in java may occur some conflict?

i don’t know anything about web service I’m the last 3 days researching a lot about, so I appreciate all the information you can share with me.

thank you in advance

2 answers

6


  1. Yes the Webservice is totally the part of the APP, summarizing the webservice is a "site" that is used only for data transmission via HTTP in a structured way, for example Json or XML instead of HTML, knowing this so your APP will access this site without needing the web browser and so will be the communication, both sending of POST/PUT how much to take data as GET. We can use REST or SOAP, which are no more than two different formats, in case you are likely to prefer the REST, read about it in:

  2. To create the webservice does not need Eclipse, it actually creates nothing it is just an IDE to facilitate, in the webservice you do not expose the database directly, because this would be a huge security breach since the Apps would need to have the authentication data from the database.

    Based on the APP makes an HTTP request to a page that returns the data in a structured way, such as Json or XML.

    I’ve searched a lot of images, but I think this one sums it up better:

    web service

    See that the Client is where are computers, cell phones, tablets and other "station" (or servers, even other sites can order a webservice), this means that the webservice caters to various locations. Web service would be the translation, that is to say it serves customers data via Web or be it outside the APP, applications just request this data or send new data and sometimes keep a local copy for chance be offline or optimize.

    The webservice can be written in many ways totally independent of the IDE as I said before, of course we use the Ides to make it easier, here are some examples of technology to use in the webservice + framework to facilitate development:

In case the connection with the bank will be in charge of the "server-side", in this case PHP, ASP.NET or Python (using framework or not).

App

If the App (app) is for Android can use ADT or Eclipse even to develop, to access a webservice you must make an HTTP request (being android is usually java, example source http://www.mkyong.com/java/how-to-send-http-request-getpost-in-java/).

Picking up data (GET)

String url = "http://[webservice].com";

URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

con.setRequestMethod("GET");

int responseCode = con.getResponseCode();
System.out.println("Código de resposta: " + responseCode);

BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream()));
String inputLine;

//Pega a resposta
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}

in.close();

//Mostra a resposta no console
System.out.println(response.toString());

Sending data (POST)

String url = "http://[webservice].com/create";
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

//envia via POST
con.setRequestMethod("POST");

//Dados POST
String urlParameters = "arg2=foo&arg2=baz";

//Cria o POST
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

int responseCode = con.getResponseCode();
System.out.println("Código de resposta: " + responseCode);

BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream()));
String inputLine;

StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}

in.close();

//Mostra a resposta no console
System.out.println(response.toString());
  • Sometimes I don’t know what to do, because I use android studio and most tutorials use eclipse, and sometimes the authors of the tutorial use some eclipse features that I can’t find in android studio, but I could understand web service by your post

  • 1

    @Tahatsu Understand this, Eclipse does nothing but make it easy, it will be good to develop your application, now if on the server/site to use PHP for example until the "notepad" serves, you can use PHP in Eclipse as well, but it will be a project totally separate from the App project, the eclipse.

  • 1

    @Tahatsu something else, usually the tutorials use Eclipse because there are http servers that use java too, ie the guy creates an android app and this uses java and creates a web site, as the eclipse is a tool to facilitate it seems that both the webservice and the app are in the same place, but are different projects these tutoral just taught to write using the eclipse to facilitate even.

  • so, this was one of my doubts, I thought they were the same project so this whole mess of my part kkkkk

  • 1

    @Tahatsu is precisely because most people, not only you, think that Ides create things, but it’s normal to make this kind of mess =) -- now just choose the language for "site" and build the webservice, i usually use eclipse to create the apps for android and pro PHP (language I use on the sites) I use Notepad++ or sublimetext

  • and another point that is creating a certain confusion, is that the video tutorial that I think is using the SOAP and you guys explaining me the REST, so I started getting more confused and only now I realized that it was SOAP, but, the ideal is to use the REST?

  • 1

    @Tahatsu the choice between SOAP and REST is yours, however I personally find REST much simpler, since it uses HTTP itself to receive and send instructions or data.

  • 1

    got it, thank you so much for your attention, now I’ll try to make my app, thank you very much

Show 3 more comments

2

1 - The web service is the part of the Android application or any other application that uses this service.

2 - You can create by Eclipse, PHP, Python or whatever is easy or convenient for you.

3 - The Webservice accesses the MYSQL, FIREBIRD, ORACLE or any other database via IP. So your bank can be on the same machine as the WEBSERVICE or other machine on the network.

4 - Webservice responds to all requests that arrive regardless of who has requested, unless it is programmed not to do so.

http://programmerguru.com/android-tutorial/android-restful-webservice-tutorial-how-to-call-restful-webservice-in-android-part-3/

  • I am using android studio in case, in a part of the tutorial I sent the author(using eclipse) click on the java class and create a webservice, should I do this in android studio? or use Service extends works?

  • 1

    I think that link that I posted plus William’s comment can answer all your questions and help you make a functional Webservice. Good luck.

  • #Taha, you are not confused Webservice with Intentservice? They are totally different things...

  • as I said, I’m very confused about this part of services

  • @Tahatsu knows what HTTP is?

  • is the information transfer protocol, certain?.

  • @Tahatsu when opening a website in the browser this is via HTTP, so the webservice is a website except that with structured data format, for example Json or XML instead of HTML, knowing this then your APP will access this site without needing the web browser and so will be the communication, both sending POST/PUT and picking up data like GET.

  • I’m reading your post, this giving to understand well

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.