How do I extract the inner exception from a soap exception in ASP.NET?

后端 未结 3 1534
被撕碎了的回忆
被撕碎了的回忆 2021-01-08 00:08

I have a simple web service operation like this one:

    [WebMethod]
    public string HelloWorld()
    {
        throw new Exception(\"HelloWorldException\"         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-08 00:46

    It IS possible!

    Service operation example:

    try
    {
       // do something good for humanity
    }
    catch (Exception e)
    {
       throw new SoapException(e.InnerException.Message,
                               SoapException.ServerFaultCode);
    }
    

    Client consuming the service:

    try
    {
       // save humanity
    }
    catch (Exception e)
    {
       Console.WriteLine(e.Message);    
    }
    

    Just one thing - you need to set customErrors mode='RemoteOnly' or 'On' in your web.config (of the service project).

    credits about the customErrors discovery - http://forums.asp.net/t/236665.aspx/1

提交回复
热议问题