如何在Android上处理SOAP方法异常

时间:2012-02-27 11:51:56

标签: android ksoap

我将请求发送到Web服务,但我得到以下异常。我该如何解决这个问题?

02-27 17:09:43.169: INFO/System.out(7904): Soap Method Error
  ->SoapFault - faultcode: 'soap:Server' faultstring:
  'Server was unable to process request. ---> Object reference not set to
   an instance of an object.' faultactor: 'null' detail:
   org.kxml2.kdom.Node@405b9a28

代码:

public String RegisterUser(String unval,String eval,String pwdval,String cpwdval,String mnoval,String fnval,
        String mnval, String lnval,String cityval,String stateval,String zcval) throws SoapFault
{
    String data = "";
    String serviceUrl = RB_Constant.RB_Webservice_URL;
    String serviceNamespace = RB_Constant.RB_Webservice_Namespace;
    String soapAction = "http://www.roadbrake.com/RegisterNewUser";
    String type_of_soap = "RegisterNewUser";
    try
    {
        SoapObject Request = new SoapObject(serviceNamespace, type_of_soap);
        Request.addProperty("strUserName", unval);
        Request.addProperty("strEmail", eval);
        Request.addProperty("strPassword", pwdval);
        Request.addProperty("strConfirmPassword", cpwdval);
        Request.addProperty("strMobileNumber", mnoval);
        Request.addProperty("strFirstName",fnval );
        Request.addProperty("strMiddleName",mnval );
        Request.addProperty("strLastName",lnval );
        Request.addProperty("strCity",cityval );
        Request.addProperty("strState",stateval );
        Request.addProperty("strZipcode",zcval );
        Request.addProperty("strSource", "Android");

        System.out.println("request ->"+Request.toString());

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(Request);

        try
        {
            HttpTransportSE androidHttpTransport = new HttpTransportSE(serviceUrl);
            androidHttpTransport.call(soapAction, envelope);
        }
        catch(Exception e)
        {
            System.out.println("Webservice calling error ->"+e.toString());
        }

        **// The app is crashed here**

        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        data = response.toString();
        System.out.println(" RB WS Response--"+response.toString());
    }
    catch(Exception e)
    {
        System.out.println("Soap Method Error ->"+e.toString());
    }
    return data;
}

1 个答案:

答案 0 :(得分:1)

您可以捕获该异常,如下所示。

catch(SoapFault sf){
    //Do something upon a SOAP exception
}