Doubts in web service

0

Personally I found the following webservice tutorial: link

Looking at the tutorial I was a bit confused about it.

1- Should the web service be part of the Android application?

For example I create a web service I put this web service on the server and then I create the application through android studio and connect to the web service?

2 - Should I create the web service through eclipse?

3 - In this tutorial it uses mysql, but I need to use firebird, in this case should I put the bank.fdb somewhere in tomcat or will the bank be accessed in the same way by the same localhost in the tutorial?

4 - I have a desktop system in delphi, if I make the web service in java can there be any conflict?

I do not know anything about web service. I've been doing a lot of research on the last 3 days, so thank you for all the information you can share with me.

Thank you in advance

    
asked by anonymous 19.05.2016 / 18:46

2 answers

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

  • To create the webservice does not need Eclipse, it does not really create anything it is just an IDE to facilitate, in the webservice you do not expose the database directly, because this would be a small security hole since the APPs would need have the database authentication data.

    On the basis of APP, it makes an HTTP request for a page that returns the data in a structured way, such as Json or XML.

    I searched for several images, but I think this one sums up better:

    SeeClientwherecomputers,mobilephones,tabletsandother"station" (or servers, even other websites can request a webservice), this means that webservice caters to several locations. Web service would be the translation, that is to say that it serves to clients data via Web or outside the APP, the applications only request this data or send new data and sometimes it keeps a local copy by chance is offline or optimized. >

    The webservice can be written in several ways totally independent of IDE as it said before, of course we use the IDEs to facilitate, it follows some examples of technology to use in the webservice + framework to facilitate the development:

  • In this case, the connection to the database will be the responsibility of server-side , in this case PHP, ASP.NET or Python (using framework or not).

    Application

    If the app is for Android you can use ADT or Eclipse to develop a webservice, you should make an HTTP request (android is usually java, source for example

    Getting 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());
    
        
    19.05.2016 / 20:27
    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 easiest or convenient for you.

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

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

    link

        
    19.05.2016 / 19:36