0

Bellow is my code for calling the service but it gives time out exception

    **DefaultHttpClient httpC = new DefaultHttpClient();
    HttpProtocolParams.setUseExpectContinue(httpC.getParams(), false);
    HttpConnectionParams.setConnectionTimeout(httpC.getParams(), 15000);
    HttpConnectionParams.setSoTimeout(httpC.getParams(), 15000);
    HttpPost httpPost = new HttpPost(WebServiceDetails.URL_WS_USER);
    httpPost.setHeader("SOAPAction", soapAction);


    try {
        se = new StringEntity(serviceXml,HTTP.UTF_8);
        se.setContentType("text/xml");
        httpPost.setEntity(se);
        BasicHttpResponse basicHttpResponse =   (BasicHttpResponse)httpC.execute(httpPost);
        HttpEntity responseEntity = basicHttpResponse.getEntity();
        InputStream inputStream = null;
        inputStream = responseEntity.getContent();
        BufferedReader r = new BufferedReader(new InputStreamReader(inputStream),1024*5);
        StringBuilder total = new StringBuilder();
        String line;
        while ((line = r.readLine()) != null) {
            total.append(line);
        }
        System.out.println("Response from service -"+total.toString());
        xmlContent=total.toString();
        System.out.println(" status Line = "+basicHttpResponse.getStatusLine());


    }catch (Exception e){e.printStackTrace();}**

it is working on emulator but not on actual device please suggest any tutorial or example if it is wrong.......

thanksx...

Sumit Patel
  • 2,547
  • 8
  • 33
  • 45

1 Answers1

0

Your real device might be experiencing slow Internet connection speed over mobile network.

To overcome Time-Out issue, I would suggest you to simply increase the time-out duration in order to buy some more time for your web sockets to complete their actions. For example:

HttpConnectionParams.setConnectionTimeout(httpC.getParams(), 40000); //40 seconds
HttpConnectionParams.setSoTimeout(httpC.getParams(), 40000);         //40 seconds
waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • please have a look i did it as HttpConnectionParams.setConnectionTimeout(httpC.getParams(), 75000); HttpConnectionParams.setSoTimeout(httpC.getParams(), 75000); but still the problem is there .... – Sumit Patel Sep 25 '12 at 09:26