locked
How to handle the exception while calling the web service? RRS feed

  • Question

  • User1081236289 posted

    Hi,

    We have developed the web application, here we are calling third party web service to fetch the data, In this case we are getting some exception while calling the WCF web service, some times we have to fix the issue in our web application, some times they are fixing the issue in WCF Web service code side.

    How to identify the exception is in our code or WCF web service exception. if we found this then we can easily tell to user please contact webservice persons or us.

    How do we identify this, What are all the exception handling that we need to add in our web application code. Please advise.

    Thanks

    Mayil.M

    Friday, August 30, 2013 10:28 PM

Answers

  • User260886948 posted

    Hi,

    We can definitely catch and handle all exceptions that happen on your service class and turn them into a FaultException or FaultException exception.

    That way, we won't "fault" (or tear down) the communications channel between our client and server.

    Even better approach would be to implement the IErrorHandler interface on our service class that provides a way to globally catch all exceptions as they happen and provide a FaultException instead, that's SOAP compliant.

    We can even turn our IErrorHandler into a configurable behavior that can be turned on or off in config.

    Please try to refer to these articles and blog posts for more details:

    #Implementing IErrorHandler:
    http://www.neovolve.com/post/2008/04/07/implementing-ierrorhandler.aspx .

    #Useful WCF behaviors: IErrorHandler:
    http://www.steverb.com/post/2008/11/24/Useful-WCF-Behaviors-IErrorHandler.aspx .

    #Exception Handling in WCF:
    http://www.codeproject.com/Articles/115006/Exception-Handling-in-WCF .

    Best Regards.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 2, 2013 9:37 PM
  • User-742633084 posted

    In addition to Amy's suggestion, I think it would be quite handy to perform a HTTP request inspection (if the webservice or WCF service use plain HTTP transport). For example, we can use fiddler to capture the HTTP request/response communication of the webservice server and client to see if the error is returned from the service (after client-side successfully send out the request):

    #Fiddler web debugging proxy
    http://fiddler2.com/home

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 3, 2013 2:26 AM

All replies

  • User260886948 posted

    Hi,

    We can definitely catch and handle all exceptions that happen on your service class and turn them into a FaultException or FaultException exception.

    That way, we won't "fault" (or tear down) the communications channel between our client and server.

    Even better approach would be to implement the IErrorHandler interface on our service class that provides a way to globally catch all exceptions as they happen and provide a FaultException instead, that's SOAP compliant.

    We can even turn our IErrorHandler into a configurable behavior that can be turned on or off in config.

    Please try to refer to these articles and blog posts for more details:

    #Implementing IErrorHandler:
    http://www.neovolve.com/post/2008/04/07/implementing-ierrorhandler.aspx .

    #Useful WCF behaviors: IErrorHandler:
    http://www.steverb.com/post/2008/11/24/Useful-WCF-Behaviors-IErrorHandler.aspx .

    #Exception Handling in WCF:
    http://www.codeproject.com/Articles/115006/Exception-Handling-in-WCF .

    Best Regards.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 2, 2013 9:37 PM
  • User-742633084 posted

    In addition to Amy's suggestion, I think it would be quite handy to perform a HTTP request inspection (if the webservice or WCF service use plain HTTP transport). For example, we can use fiddler to capture the HTTP request/response communication of the webservice server and client to see if the error is returned from the service (after client-side successfully send out the request):

    #Fiddler web debugging proxy
    http://fiddler2.com/home

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 3, 2013 2:26 AM