I have a simple web service operation like this one:
[WebMethod]
public string HelloWorld()
{
throw new Exception("HelloWorldException");
return "Hello World";
}
And then I have a client application that consumes the web service and then calls the operation. Obviously it will throw an exception :-)
try
{
hwservicens.Service1 service1 = new hwservicens.Service1();
service1.HelloWorld();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
In my catch-block, what I would like to do is extract the Message of the actual exception to use it in my code. The exception caught is a SoapException
, which is fine, but it's Message
property is like this...
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Exception: HelloWorldException
at WebService1.Service1.HelloWorld() in C:\svnroot\Vordur\WebService1\Service1.asmx.cs:line 27
--- End of inner exception stack trace ---
...and the InnerException
is null
.
What I would like to do is extract the Message
property of the InnerException
(the HelloWorldException
text in my sample), can anyone help with that? If you can avoid it, please don't suggest parsing the Message
property of the SoapException
.