我有一个 ASP.NET WebService
,如果输入条件错误,它会抛出异常。
如果它被另一个 C#/ASP.NET 应用程序客户端调用,它们可以正确解释异常。
但是如果它被 ksoap2 调用,我会得到一个 HTTP 状态 500。
我可以知道什么是我处理此异常的最佳方法,最重要的是检索该异常中的错误消息,以便我可以向用户显示。
提前致谢。
---- 添加以下代码:
ASP.NET 网络服务
[WebMethod]
public void Test()
{
throw new Exception("This is a test message");
}
安卓 ksoap2 客户端
// 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();
}