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

前端 未结 3 1704
忘掉有多难
忘掉有多难 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
    }
    
    0 讨论(0)
  • 2021-02-19 19:54

    Catch the SoapException instance. That way you can access its information:

    try {
         service.StartGame();
    } catch (SoapException e)  {
        // The variable 'e' can access the exception's information.
    }
    
    0 讨论(0)
  • 2021-02-19 19:55
    catch (SoapException soapEx) 
    {
      //Do something with soapEx
    }
    
    0 讨论(0)
提交回复
热议问题