As with a great many software abstraction layers purportedly removing the need to understand the their underlying technology, WCF can be accused of being a wee bit of a leaky abstraction.
Microsoft’s noble intent to distil all interprocess communication into the ABC of WCF endpoints is, in my humble opinion, for the most part a great success and a pleasure to work with. But, as with many abstractions, the devil is always in the detail and in reality you would never really treat any of your endpoints arbitrarily simply as WCF. In my recent experience of working with WCF, an appreciation of their underlying transport mechanisms has actually proved vital in dealing the many and varied idiosyncrasies they exhibit and further that they exhibit when plumbed into the WCF channels you’re using. Most specifically when you need to quickly diagnose issues that have blocked one of your MSMQ queues with a poison message, a means of peering into the WCF channel at runtime has proved invaluable. The problem, as ever, when dealing with such a new technology has been how best to discover these idiosyncrasies.
Adding run time diagnostics to WCF MSMQ exceptions.
WCF comes complete with a great many extension points. Service definitions can be easily extended by adding proprietary Service Behaviour attributes to them (in fact, if you’re using a version of MSMQ prior to 4.0, the only means of moving a poison message onto a poison message queue is by adding a Service Behaviour that reacts to an instance MsmqPoisonMessageException.) In the case of exception handling each of the channel dispatchers in a WCF service can have a collection of ErrorHandlers which behave much like a chain of responsibility.
A generic HanldeException implementation is shown below.
-
<br />
-
public bool HandleError(Exception error)<br />
-
{</p>
-
<p> //perform custom error handler actions</p>
-
<p> //indicate that this exception has been handled<br />
-
return true;<br />
-
}<br />
As well as allowing you to add a bespoke handler to your service, by returning false from the HandleError call (indicating to the code managing the exception that it needs to pass it on to the next link of the chain) you can also introduce runtime diagnostics without otherwise interferring with the remaining Service Behaviors (keep in mind that in many cases once the queue has thrown an MsmqPoisonMessageException you will normally have lost any opportunity to delve further into the root cause of the exception).
To take advantage of this we can introdude an ErrorDiagnosticsBehaviourAttribute and ErrorDiagnosticsHandler which can leverage any runtime or simple trace strategy available to us. In the case of this example we had remote trace information available through another WCF based solution that allowed us to inspect trace events in our running applications in real time but even a more simple Debug.WriteLine call coupled wih a running instance of DebugView could suffice.
To put it all together then, you first need to define a concrete WCF error handler by implementing the IErrorHandler interface. For the purposes of diagnostics you need only actually implement the HandleError method.
-
<br />
-
using System;<br />
-
using System.ServiceModel.Channels;<br />
-
using System.ServiceModel.Dispatcher;<br />
-
using LU.Diagnostics;</p>
-
<p>namespace LU.Rti.Library.ServiceModel.ErrorHandlers<br />
-
{<br />
-
public class ErrorDiagnosticsHandler : IErrorHandler<br />
-
{<br />
-
private static EventSink _eventSink;<br />
-
public static EventSink EventSink<br />
-
{<br />
-
get { return _eventSink; }<br />
-
set { _eventSink = value; }<br />
-
}</p>
-
<p> public void ProvideFault(Exception error, MessageVersion version, ref Message fault)<br />
-
{<br />
-
}</p>
-
<p> /// Trace exception messages inside the WCF framework<br />
-
/// to an LU.Diagnostics client<br />
-
public bool HandleError(Exception error)<br />
-
{<br />
-
TraceException(error);</p>
-
<p> return false;<br />
-
}</p>
-
<p> private static void TraceException(Exception error)<br />
-
{<br />
-
if (_eventSink != null)<br />
-
_eventSink.LogEvent(EventSeverity.High, error);<br />
-
}<br />
-
}<br />
-
}<br />
Once this is available it can be added into your WCF service by defining a concrete Service Behavior attribute as below.
-
<br />
-
using System;<br />
-
using System.Collections.ObjectModel;<br />
-
using System.ServiceModel;<br />
-
using System.ServiceModel.Channels;<br />
-
using System.ServiceModel.Description;<br />
-
using System.ServiceModel.Dispatcher;</p>
-
<p>namespace LU.Rti.Library.ServiceModel.ErrorHandlers<br />
-
{<br />
-
public class ErrorDiagnosticsBehaviourAttribute : Attribute, IServiceBehavior<br />
-
{<br />
-
private ErrorDiagnosticsHandler _handler =
new ErrorDiagnosticsHandler
();</p>
-
<p> void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)<br />
-
{<br />
-
}</p>
-
<p> void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,<br />
-
Collection endpoints,<br />
-
BindingParameterCollection bindingParameters)<br />
-
{<br />
-
}</p>
-
<p> void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)<br />
-
{<br />
-
foreach (ChannelDispatcherBase dispatcher in serviceHostBase.ChannelDispatchers)<br />
-
((ChannelDispatcher) dispatcher).ErrorHandlers.Add(_handler);<br />
-
}<br />
-
}<br />
-
}<br />
The main job of this attribute is to allow the running service to inject your custom handler into it’s channel dispatchers exception handling behaviour. This is achieved by adding the attribute to your service definition. Diagnostics can then be made available by adding your new attribute to the definition of any service that you feel may require it.
-
<br />
-
[ErrorDiagnosticsBehavior]<br />
-
public class ExampleService : IExampleService<br />
-
{<br />
-
//service implementation<br />
-
}<br />
Whilst this strategy doesn’t deal directly with an y of the problems that may occur during your implementation of WCF using MSMQ, I certainly found it helped enormously in discovering the root causes of issues that can block communication in your queues.
serenity firefly movieeducation sex moviessex clip moviemovies porn sexdownloads shaved movie pussyshop girl moviemovies lesbian sinfulsnatch movie quotesporn movies spankingmovie girls spice script for
t290i sonyericsson ringtones alabama120c ringtonescingular ringtone adam feat fsoftware ringtone 3600 composercell lg 4050 ringtone phonecomposable samsung free a300 ringtoneafi polyphonis ringtonestamil nokia 1600 ringtone Map
manager accreditationbad credit loan $5000 withadding to credit website your cardsalaska cards credit airlinescredit alaska airline cardsaccreditation home child care familycredit advantage american cardstolen cards after credit are Map
account allinanchor adult merchant credit cardaustralia hypnosis vic course accreditedfor adresses creditorscredit ammends counselingamba amba accreditation etaccept knuckle card buster creditaccreditation aacsb et aacsbamerican card express credit black titanium Map
Share This Post