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

后端 未结 3 1544
被撕碎了的回忆
被撕碎了的回忆 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:59

    I ran into something similar a bit ago and blogged about it. I'm not certain if it is precisely applicable, but might be. The code is simple enough once you realize that you have to go through a MessageFault object. In my case, I knew that the detail contained a GUID I could use to re-query the SOAP service for details. The code looks like this:

    catch (FaultException soapEx)
    {
        MessageFault mf = soapEx.CreateMessageFault();
        if (mf.HasDetail)
        {
            XmlDictionaryReader reader = mf.GetReaderAtDetailContents();
            Guid g = reader.ReadContentAsGuid();
        }
    }
    

提交回复
热议问题