androidksoap2

Parsing soapfault error code and error message android


I am calling a web service in android project using ksoap2.

I am receiving WS exception like below . Which is expected result for the input I am passing.

SoapFault - faultcode: 'soapenv:Server' faultstring: 'test.exceptions.WsException' faultactor: 'null' detail: org.kxml2.kdom.Node@5ebf64f

There is errorCode and errorMessage in detail field. But I am having problem while parsing it. Can anyone help how can I parse it.

Thanks


Solution

  • I solved it like below by handling in exception.

         catch (SoapFault sf)
            {
    
                String errorCode="",errorMessage="";
                Element el=sf.detail.getElement(0);
    
    
                for(int i=0;i<=el.getChildCount();i++)
                {
    
                    el=el.getElement(0);
                    if(el.getName().equals("WsException"))
                    {
                        Element elementec=el.getElement(0);
                        errorCode=elementec.getChild(0).toString();
    
                        Element elementem=el.getElement(1);
                        errorMessage=elementem.getChild(0).toString();
    
    
                    }
    
                }
    
                result="error Code "+ errorCode + "error Message " + errorMessage ;
    
            }