You may want to try Jt secure Web Services for Android: -Java Pattern Oriented Framework, An application of the Messaging Design Pattern IBM Technical Library http://www.ibm.com/developerworks/webservices/library/ws-designpattern/index.html
- Messaging Design Pattern and a distributed Component/Service Model https://jt.dev.java.net/files/documents/5553/149793/MDPdistributedModel.pdf The following code is taken from the Jt.JtURL component (invoked by the Jt.rest.JtRestService component) private String doPost (String request) { URLConnection urlConn; URL destURL; DataOutputStream outStream; DataInputStream inStream; int c; StringBuffer sBuffer = new StringBuffer (); if (request == null) return null; if (url == null) return null; handleTrace ("request:" + request); try { destURL = new URL (url); urlConn = destURL.openConnection(); urlConn.setDoOutput(true); urlConn.setDoInput(true); urlConn.setRequestProperty("Content-length", "" + request.length()); outStream = new DataOutputStream (urlConn.getOutputStream()); outStream.writeBytes(request); outStream.close (); inStream = new DataInputStream (urlConn.getInputStream()); while ((c = inStream.read()) >= 0) { sBuffer.append((char) c); } } catch (Exception ex) { handleException (ex); } return ((String) sBuffer.toString()); } If feasible you may want to try without GZIP. It should be a bit faster. On Nov 18, 6:00 pm, Wipeout <4.9fi...@gmail.com> wrote: > Hey guys, > This is my first post to the Android Developers group. I have been > working with HTTP communication in the Android SDK and have noticed > that calls to a web service through my app are very slow (taking > 800+ms on high speed wifi). They take less than 100ms if I call the > web service through the phone's browser. I am developing on a Google > Nexus One. The size of the data returned is very small, <1K. I have > tried enabling gzip compression, and that helps slightly but I assume > there is another problem at hand. I have tried using SOAP with the > ksoap2-android library, as well as making things simple using > HttpClient and InputStreamReader. Below is my code for the fastest I > can make the app perform; using no SOAP, and using GZIP compression. I > apologize for the lengthy code -- I think all of it is beneficial for > determining the best way to make this request and response happen > faster. > > [code] > public String GetRest() > { > > long startTime = System.currentTimeMillis(); > String result = ""; > > Log.v("time", "Beginning rest: " + (System.currentTimeMillis() - > startTime) + "ms"); > > try > { > HttpClient client = new DefaultHttpClient(); > HttpGet request = new HttpGet("https://usad.enlyght.com/ws/ > AndroidService.asmx/GetWebServiceVersion"); > request.addHeader("Accept-Encoding", "gzip"); > > Log.v("time", "Before call: " + (System.currentTimeMillis() - > startTime) + "ms"); > HttpResponse response = client.execute(request); > InputStream instream = response.getEntity().getContent(); > Header contentEncoding = response.getFirstHeader("Content- > Encoding"); > if (contentEncoding != null && > contentEncoding.getValue().equalsIgnoreCase("gzip")) { > instream = new GZIPInputStream(instream); > } > InputStreamReader isreader = new InputStreamReader(instream); > BufferedReader reader = new BufferedReader(isreader); > StringWriter sw = new StringWriter(); > > String read; > while ((read = reader.readLine()) != null) { > result += read; > } > > client.getConnectionManager().shutdown(); > } > catch (Exception e) {} > Log.v("time", "End rest: " + (System.currentTimeMillis() - > startTime) + "ms"); > > return result; > } > [/code] > > Regards, > Adam Smith > Norsoft -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en