ANDROID:KSOAP2 HttpsTransportSE慢响应或超时

时间:2014-03-03 13:31:21

标签: java android ksoap2

我正在使用HttpsTransportSE来调用webservices。反复调用需要回复1-2s的Web服务。然后有一个需要30-45秒或返回超时的呼叫(设置在45秒)。此问题仅在WIFI上的3G信号上完美地发生。

        public SoapObject CallWS(Object object, ArrayList<Tuples> params,
        String SOAP_ACTION, String METHOD_NAME, String NAMESPACE, String serviceURL) {
    SoapObject response = null;
    //try {
        // Generate soap object with WS-namespace and WS-method name
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        // Parameters for WS method
        for (int i = 0; i < params.size(); i++) {
            request.addProperty(params.get(i).getLeft().toString(), params
                    .get(i).getRight().toString());
        }           
        // Create soap envelope
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        envelope.headerOut = new Element[1]; 
        envelope.headerOut[0] = buildAuthHeader(NAMESPACE,"trak8","g3s0"); 

        // Add mapping for complex parameter
        envelope.addMapping(NAMESPACE, "Object", new Object().getClass());          
        TrustManagerManipulator.allowAllSSL();

        Log.i("NAMESPACE",NAMESPACE);
        Log.i("METHOD_NAME",METHOD_NAME);
        Log.i("URL2",serviceURL);

        //HttpTransportSE aht = new HttpTransportSE(serviceURL, 10000);

        String[] serviceURLSplit = serviceURL.split("//");  
        String[] serviceURLSplitMethod = serviceURLSplit[1].split("/"); 
        HttpsTransportSE aht = new HttpsTransportSE(serviceURLSplitMethod[0], 443,"/"+serviceURLSplitMethod[1], 45000);
        List<HeaderProperty> headerList = new ArrayList<HeaderProperty>();
        headerList.add(new HeaderProperty("Connection", "keep-alive"));
        try {
            Log.i("StatusCall", "calling ws"+METHOD_NAME); // For debbug only
            aht.call(SOAP_ACTION, envelope,headerList);
            response = (SoapObject) envelope.getResponse();

            Log.i("StatusCall", "response successfully recived"); // For debbug
                                                                // only

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

    return response;
  }

`

0 个答案:

没有答案