Как обработать исключение метода SOAP на Android - PullRequest
0 голосов
/ 27 февраля 2012

Я отправил запрос в веб-сервис, но получил следующее исключение. Как я могу решить эту проблему?

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 Ответ

1 голос
/ 27 февраля 2012

Вы можете поймать это исключение, как показано ниже.

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