Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent a WCF service from enter a faulted state?

Tags:

c#

.net

wcf

msmq

I have a WCF Service that should not enter the faulted state. If there's an exception, it should be logged and the service should continue uninterrupted. The service has a one-way operation contract and is reading messages from an MSMQ.

My problems are twofold:

  1. The service appears to be swallowing an exception/fault so I am unable to debug it. How do I get the service to expose the exception so that I can log or handle it?
  2. The service is entering into a faulted state after this exception is swallowed. How do I prevent the service from entering into a faulted state?
like image 875
Guy Avatar asked Nov 24 '08 22:11

Guy


People also ask

What is faulted state?

Yes, the Faulted State error usually means that an unhandled exception is thrown on the server side. To determine the exact cause of this error we need the following: The source code of the client and server applications to see exactly how they are configured. A screenshot of the error.


2 Answers

The official documentation on how to handle Faults is here:

with the main page being at Channel Model Overview

There's a nice state diagram showing how things happen:

enter image description here

like image 168
David d C e Freitas Avatar answered Oct 08 '22 08:10

David d C e Freitas


Most, if not all exceptions can be seen in the WCF Trace (Configuring Tracing) and the trace is best viewed with the Service Trace Viewer.

Obviously, this is not something you should have running all day in a production environment, but it helps in troubleshooting anyway.

Apart from that, note that oneways may not run as a true "fire and forget" depending on the SessionMode you use. If you have your service configured for SessionMode.Allowed or even SessionMode.Required, the oneway operation will run as if it was not oneway at all (this can be observed when using oneways over the netTcpBinding). To be frank, however, I don't know if that changes the type of exceptions you can get, or when you get them. However, in any case, you should get an exception if the request could not be send at all. AFAIK, the oneway "ends" when it is successfully enqued on the server side. So there is some place for (WCF framework related) exceptions until then (serialization/deserialization comes to mind).

Then, such framework related exceptions are best seen (even an IErrorHandler doesn't get them all due to the fact when it is called in the request/response-flow) using the above mentioned trace / traceviewer.

like image 24
Christian.K Avatar answered Oct 08 '22 08:10

Christian.K