开发者

What is the best alternative to calling web services with an Android App

开发者 https://www.devze.com 2023-03-25 04:24 出处:网络
We can make Webservice call in android app by creating HttpURLConnection and POST request. Something like the following

We can make Webservice call in android app by creating HttpURLConnection and POST request. Something like the following

    httpURLConnection.setRequestMethod("POST");
    httpURLConnection.setRequestProperty("Connection", "keep-alive");
    httpURLConnection.setRequestProperty("Content-Type", "text/xml");
    httpURLConnection.setRequestProperty("SendChunked", "True");
    ....
    httpURLConnection.connect();
    OutputStream out = httpURLConnection.getOutputStream();
    out.write("request data in soap format");// send request
开发者_C百科    InputStream response = httpURLConnection.getInputStream(); //receive response

Here I have to create SOAP like xml to send data and also receive data in that format. Is there any better approach to call webservice?

What is the best alternative to calling web services with an Android App


You use SOAP or REST approach for your webservice. See the programs from

REST and SOAP webservice in android

* SOAP *

Pros:

  • Langauge, platform, and transport agnostic
  • Designed to handle distributed computing environments
  • Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors
  • Built-in error handling (faults)
  • Extensibility

Cons:

  • Conceptually more difficult, more "heavy-weight" than REST
  • More verbose
  • Harder to develop, requires tools

* REST *

Pros:

  • Language and platform agnostic
  • Much simpler to develop than SOAP
  • Small learning curve, less reliance on tools
  • Concise, no need for additional messaging layer
  • Closer in design and philosophy to the Web

Cons:

  • Assumes a point-to-point communication model--not usable for distributed computing environment where message may go through one or more intermediaries
  • Lack of standards support for security, policy, reliable messaging, etc., so services that have more sophisticated requirements are harder to develop ("roll your own")
  • Tied to the HTTP transport model
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号