I have an ASP.NET WebService
which will throw exception if the input condition is wrong.
If it is invoked by another C# / ASP.NET application client, they can interpret the exception correctly.
But if it is invoked by ksoap2, I will get a HTTP Status 500 instead.
May I know what is the best way for me to handle this exception, and most importantly retrieve the error message within that exception, so that I can display to the user.
Thanks in advance.
---- Adding the code below:
[WebMethod]
public void Test()
{
throw new Exception("This is a test message");
}
// There are some details been obmitted. Just assume the code below works ok?
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 60000);
try
{
// The Web Service in ASPNET is invoked successfully. And an Exception is thrown.
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject obj;
obj = (SoapObject)envelope.getResponse();
}
catch (Exception e)
{
// Manage to reach here. But How can I retrieve the Fault Message "This is a test message"?
e.printStackTrace();
}
http://www.c-sharpcorner.com/UploadFile/88b6e5/how-to-call-web-service-in-android-using-soap/请参阅此链接,它将为您提供帮助。如果您发布代码,则意味着对您有很大帮助。
If you were using version 3.0.0 of ksoap2-android and you received a SOAP fault in the response with a corresponding HTTP 500 error code you would not have received the SOAP fault object.
This has been fixed in version 3.0.1: https://code.google.com/p/ksoap2-android/wiki/ProjectNews .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.