SoapFault - faultcode:' soap:Server' faultstring:

时间:2015-05-29 03:32:37

标签: android web-services android-asynctask android-ksoap2

当我使用Ksoap2从android调用dotnet webservice时,有时我会收到错误。我必须在AsyncTask类中从android调用多个webservice方法。有时候所有方法都通过,有时会显示多个错误,如下图或 java.net.SocketException:recvfrom failed:ECONNRESET(连接由对等方重置) W / System.err(27972):at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)类似的东西。如何解决这个问题。

enter image description here

这是我的源代码

private static String URL = "http://172.230.0.22/pos_cashsale/Service1.asmx";

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  CheckProductGroupInfoHasNew();
 CheckCustomerInfoHasNew();
 CheckProductInfoHasNew();
 }

 private void CheckCustomerInfoHasNew() {
    String _LastDate = "";
    CVLastUpdateDate = "";
    _LastDate = DAL
            .SelectCmd("Select LAST_UPDATE_DATE From MAS_CUSTOMER_INFO Order By LAST_UPDATE_DATE Desc LIMIT 1");

    String lFormatTemplate = "yyyy-MM-dd'T'hh:mm:ss";
    CVLastUpdateDate = getSOAPDateString(_LastDate, lFormatTemplate);

    AsyncSyncData _AsyncSyncData = new AsyncSyncData();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        _AsyncSyncData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                "CV");
    else
        _AsyncSyncData.execute("CV");
}

 private void CheckProductGroupInfoHasNew() {
    String _LastDate = "";
    PGLastUpdateDate = "";
    _LastDate = DAL
            .SelectCmd("Select LAST_UPDATE_DATE From MAS_SAP_PRODUCT_GROUP Order By LAST_UPDATE_DATE Desc LIMIT 1");

    String lFormatTemplate = "yyyy-MM-dd'T'hh:mm:ss";
    PGLastUpdateDate = getSOAPDateString(_LastDate, lFormatTemplate);

    AsyncSyncData _AsyncSyncData = new AsyncSyncData();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        _AsyncSyncData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                "PG");
    else
        _AsyncSyncData.execute("PG");
}
 private void CheckProductInfoHasNew() {
    String _LastDate = "";
    PCLastUpdateDate = "";
    _LastDate = DAL
            .SelectCmd("Select LAST_UPDATE_DATE From MAS_PRODUCT_INFO Order By LAST_UPDATE_DATE Desc LIMIT 1");

    String lFormatTemplate = "";

    if (_LastDate.length() == 23) {
        lFormatTemplate = "yyyy-MM-dd'T'hh:mm:sss";
    } else if (_LastDate.length() == 22) {
        lFormatTemplate = "yyyy-MM-dd'T'hh:mm:ss";
    } else if (_LastDate.length() == 21) {
        lFormatTemplate = "yyyy-MM-dd'T'hh:mm:s";
    } else if (_LastDate.length() == 21) {
        lFormatTemplate = "yyyy-MM-dd'T'hh:mm";
    }

    // String lFormatTemplate = "yyyy-MM-dd'T'hh:mm:ss";
    PCLastUpdateDate = getSOAPDateString(_LastDate, lFormatTemplate);

    AsyncSyncData _AsyncSyncData = new AsyncSyncData();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        _AsyncSyncData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                "PC");
    else
        _AsyncSyncData.execute("PC");
}

 class AsyncSyncData extends AsyncTask<String, String, String> {
    @Override
    protected String doInBackground(String... params) {
        Log.i("AsyncSyncData", "doInBackground" + " " + params);
        String _Query = ""; 
            if (params[0].toString().equals("PG")) {
                responsePGroupJSON = "";
                responsePGroupJSON = invokeJSONWS("LastUpdateDate",
                        PGLastUpdateDate, "", "", "GetProductGroup");
            } else if (params[0].equals("PC")) {
                responsePrdCodeJSON = "";
                responsePrdCodeJSON = invokeJSONWS("LastUpdateDate",
                        PCLastUpdateDate, "OrgCode", UserInfo.OrgCode,
                        "GetProductCode");
            } else if (params[0].equals("CV")) {
                responseCVCodeJSON = invokeJSONWS("LastUpdateDate",
                        CVLastUpdateDate, "OrgCode", UserInfo.OrgCode,
                        "GetCustomerInfo"); 

        return params[0].toString();
    }
@Override
    protected void onPostExecute(String result) { 
        try {
            if (result.equals("PG")) {
                BindPGFromWeb(responsePGroupJSON);  
            } else if (result.equals("CV")) {
                BindCustomerInfoFromWeb(responseCVCodeJSON);  
            } else if (result.equals("PC")) {
                BindProductCodeFromWeb(responsePrdCodeJSON); 
                if (progressDialog != null && progressDialog.isShowing()) {
                    progressDialog.dismiss();
                } SyncActivity.this.finish(); }  
        } catch (Exception ex) {
            ex.printStackTrace(); 
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss(); }
            SyncActivity.this.finish(); 
        }  
    }
@Override
    protected void onPreExecute() {//create dialog}

 public static String invokeJSONWS(String Name1, String Value1,
        String Name2, String Value2, String methName) {
    String responseJSON = "";
    // Create request
    try {
        SoapObject request = new SoapObject(NAMESPACE, methName);

        if (!Value1.equals("")) {
            // Property which holds input parameters
            PropertyInfo paramPI = new PropertyInfo();
            // Set Name
            paramPI.setName(Name1);
            // Set Value
            paramPI.setValue(Value1);
            // Set dataType
            paramPI.setType(String.class);
            // Add the property to request object
            request.addProperty(paramPI);
        }

        if (!Value2.equals("")) {
            // Property which holds input parameters
            PropertyInfo paramPI2 = new PropertyInfo();

            // Set Name
            paramPI2.setName(Name2);
            // Set Value
            paramPI2.setValue(Value2);
            // Set dataType
            paramPI2.setType(String.class);
            // Add the property to request object
            request.addProperty(paramPI2);
        }

        // Create envelope
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER10);
        envelope.dotNet = true;
        // Set output SOAP object
        envelope.setOutputSoapObject(request);
        // Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,
                10000);

        try {
            // Invoke web service
            androidHttpTransport.call(SOAP_ACTION + methName, envelope);
            // Get the response
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

            // SoapPrimitive response = (SoapPrimitive)envelope.bodyIn;
            // Assign it to static variable
            responseJSON = response.toString();

        } catch (Exception e) {
            Log.e("invokeJSONWS", methName);
            e.printStackTrace();

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    Log.i("responseJSON", responseJSON);
    return responseJSON;
}

0 个答案:

没有答案