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