How do you catch a thrown soap exception from a web service?

前端 未结 3 1922
忘掉有多难
忘掉有多难 2021-02-19 19:05

I throw a few soap exceptions in my web service successfully. I would like to catch the exceptions and access the string and ClientFaultCode that are called with the exception.

3条回答
  •  没有蜡笔的小新
    2021-02-19 19:38

    You may want to catch the specific exceptions.

    try
    {
         service.StartGame();
    }
    catch(SoapHeaderException)
    {
    // soap fault in the header e.g. auth failed
    }
    catch(SoapException x)
    {
    // general soap fault  and details in x.Message
    }
    catch(WebException)
    {
    // e.g. internet is down
    }
    catch(Exception)
    {
    // handles everything else
    }
    

提交回复
热议问题