0

I have a very simple WCF SOAP service that does some changes in DB upon every call and returns some response. I'm also using ServiceChannel to call it from my client side code.

I want to make sure that my client-side code does not just fail when service is too busy, so have implemented a Retry pattern to retry the service call if exception is caught. However, i don't want to retry if exception is caused by my code on WCF server side (if it's not connection-related, or if any OperationContract code was executed anyway (a timeout doesn't mean it wasn't, right?)).

So i want to retry only if

  1. I've sent a request
  2. Caught an exception
  3. None of the server side code in my OperationContract method was executed

Microsoft article (link above) has almost no information about what types of exceptions exactly are transient. What exception types should I use to catch exactly what I need? Or how should I filter them?

Arsen Magomedov
  • 480
  • 8
  • 21
  • 1
    I am not sure you can ever know client side if **none** of the server code was executed. If the packet went to the server but the client gets no response, there is absolutely no way of learning what happens server side. Thus, in case of any exception a retry makes sense, just make sure you handle replies correctly, for example by including a unique ids with messages and comparing incoming id to the list of previously stored ids. – Wiktor Zychla Sep 25 '15 at 19:44
  • I think the article you mentioned does cover handling of Transient exception. Did you take a look at `IsTransient(Exception ex)` method definition. `WebExceptionStatus.ConnectionClosed, WebExceptionStatus.Timeout, WebExceptionStatus.RequestCanceled }. Contains(webException.Status` – vendettamit Sep 25 '15 at 20:51

1 Answers1

-1

Inside your WCF service implementation, within your operation contracts catch exceptions that happens throughout the execution of the code and return specific FaultException to signal your client that your service side code has run. May be put a special fault code or start your Fault Exception message with a predefined sub string. On your client side once you catch a Fault exception check if the sub string exists (or the specific fault code s you set on your service code), if these exist that means your service side code has run and you do not need to retry otherwise you can retry. You could also catch other exception types and retry as well.

Dogu Arslan
  • 3,292
  • 24
  • 43