Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>SOAP</strong></p> <p>Pros:</p> <blockquote> <ul> <li>Langauge, platform, and transport agnostic</li> <li>Designed to handle distributed computing environments</li> <li>Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors</li> <li>Built-in error handling (faults)</li> <li>Extensibility</li> </ul> </blockquote> <p>Cons:</p> <blockquote> <ul> <li>Conceptually more difficult, more "heavy-weight" than REST</li> <li>More verbose</li> <li>Harder to develop, requires tools</li> </ul> </blockquote> <p><strong>REST</strong></p> <p>Pros:</p> <blockquote> <ul> <li>Language and platform agnostic</li> <li>Much simpler to develop than SOAP</li> <li>Small learning curve, less reliance on tools</li> <li>Concise, no need for additional messaging layer</li> <li>Closer in design and philosophy to the Web</li> </ul> </blockquote> <p>Cons:</p> <blockquote> <ul> <li>Assumes a point-to-point communication model--not usable for distributed computing environment where message may go through one or more intermediaries</li> <li>Lack of standards support for security, policy, reliable messaging, etc., so services that have more sophisticated requirements are harder to develop ("roll your own")</li> <li>Tied to the HTTP transport model</li> </ul> </blockquote> <h2>Example of REST</h2> <p>Use apache http jar</p> <pre><code>public void callRestWebService(){ System.out.println(".....REST.........."); HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(wsdlURL); request.addHeader("company name", "abc"); request.addHeader("getAccessNumbers","http://service.xyz.com/"); ResponseHandler&lt;String&gt; handler = new BasicResponseHandler(); try { result = httpclient.execute(request, handler); System.out.println("..result..."+result); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); } // end callWebService() } </code></pre> <h2>Example of SOAP</h2> <p>You can use either ksoap or create soap xml by yourself and send to url </p> <pre><code>private boolean callSOAPWebService() { OutputStream out = null; int respCode = -1; boolean isSuccess = false; URL url = null; HttpsURLConnection httpURLConnection = null; try { url = new URL(wsdlURL); httpURLConnection = (HttpsURLConnection) url.openConnection(); do { // httpURLConnection.setHostnameVerifier(DO_NOT_VERIFY); httpURLConnection.setRequestMethod("POST"); httpURLConnection .setRequestProperty("Connection", "keep-alive"); httpURLConnection .setRequestProperty("Content-Type", "text/xml"); httpURLConnection.setRequestProperty("SendChunked", "True"); httpURLConnection.setRequestProperty("UseCookieContainer", "True"); HttpURLConnection.setFollowRedirects(false); httpURLConnection.setDoOutput(true); httpURLConnection.setDoInput(true); httpURLConnection.setUseCaches(true); httpURLConnection.setRequestProperty("Content-length", getReqData().length + ""); httpURLConnection.setReadTimeout(10 * 1000); // httpURLConnection.setConnectTimeout(10 * 1000); httpURLConnection.connect(); out = httpURLConnection.getOutputStream(); if (out != null) { out.write(getReqData()); out.flush(); } if (httpURLConnection != null) { respCode = httpURLConnection.getResponseCode(); Log.e("respCode", ":" + respCode); } } while (respCode == -1); // If it works fine if (respCode == 200) { try { InputStream responce = httpURLConnection.getInputStream(); String str = convertStreamToString(responce); System.out.println(".....data....." + new String(str)); // String str // =Environment.getExternalStorageDirectory().getAbsolutePath()+"/sunilwebservice.txt"; // File f = new File(str); // // try{ // f.createNewFile(); // FileOutputStream fo = new FileOutputStream(f); // fo.write(b); // fo.close(); // }catch(Exception ex){ // ex.printStackTrace(); // } } catch (Exception e1) { e1.printStackTrace(); } } else { isSuccess = false; } } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { out = null; } if (httpURLConnection != null) { httpURLConnection.disconnect(); httpURLConnection = null; } } return isSuccess; } public static String createSoapHeader() { String soapHeader = null; soapHeader = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;" + "&lt;soap:Envelope " + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + "&gt;"; return soapHeader; } public static byte[] getReqData() { StringBuilder requestData = new StringBuilder(); requestData.append(createSoapHeader()); requestData .append("&lt;soap:Body&gt;" + "&lt;getAccessNumbers" + " xmlns=\"http://service.xyz.com.com/\"" + "&lt;/getAccessNumbers&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt;"); return requestData.toString().trim().getBytes(); } private static String convertStreamToString(InputStream is) throws UnsupportedEncodingException { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload