I'm trying to implement reliable messaging so I can detect communication
failures between the client and the server.
I would like to be notified of comms failures on the client side and the
server side. I've successfully hooked up the Faulted event on the client side
using my DuplexChannel and this seems to work quite nicely. If I kill my
server (hosted as a windows service), the client gets the Faulted event after
my InactivityTimeout of 3 seconds kick in.
However, on the server side I'm unable to get the Faulted event raised by
the ServiceHost. If I kill my client I never see the Faulted event raised by
my ServiceHost.
Here is the snippet of service code for setting up the reliable tcp binding:
_serviceHostKV = new ServiceHost(typeof(KVImaging));
NetTcpBinding reliabletcpBinding = new NetTcpBinding();
reliabletcpBinding.Security.Mode = SecurityMode.None;
reliabletcpBinding.SendTimeout = ts;
// Select a receive timeout of TimeSpan.MaxValue which effectively
gives an infinite timeout.
// NB. Rather confusingly this is not the time it takes to receive a
call, but is the timeout interval
// between received calls
reliabletcpBinding.ReceiveTimeout = TimeSpan.MaxValue;
// Switch on reliable sessions
reliabletcpBinding.ReliableSession.Enabled = true;
// Timeout on arbitary value of 3 seconds
reliabletcpBinding.ReliableSession.InactivityTimeout =
TimeSpan.FromSeconds(3);
//Add the endpoint
_serviceHostKV.AddServiceEndpoint(typeof(IdaqProtocolCom.IVolumeView),
reliabletcpBinding, iDaqServerAddressKV);
// Hook up the faulted event for the kV service
_serviceHostKV.Faulted += new EventHandler(ChannelFaulted);
// Open the ServiceHosts
_serviceHostKV.Open();
I've configured a diagnostics trace lister into the service and it looks
like the Inactivity Timeout is detected, please see the following:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131075</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2007-09-17T12:35:14.3994114Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{120b8c7c-5a59-4122-a1c0-812954a341a5}" />
<Execution ProcessName="XXXXXX.YYYYYY.IdaqServer" ProcessID="964"
ThreadID="6" />
<Channel />
<Computer>CD04109</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord
xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/en-GB/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
<Description>Throwing an exception.</Description>
<AppDomain>XXXXXX.YYYYYY.IdaqServer.exe</AppDomain>
<Exception>
<ExceptionType>System.ServiceModel.CommunicationException,
System.ServiceModel, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The inactivity timeout of (00:00:03) has been exceeded.</Message>
<StackTrace>
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at
System.ServiceModel.Channels.InputQueue`1.AsyncQueueReader.End(IAsyncResult
result, T& value)
at System.ServiceModel.Channels.InputQueue`1.EndDequeue(IAsyncResult result,
T& value)
at System.ServiceModel.Channels.DuplexChannel.EndTryReceive(IAsyncResult
result, Message& message)
at
System.ServiceModel.Dispatcher.DuplexChannelBinder.EndTryReceive(IAsyncResult
result, RequestContext& requestContext)
at
System.ServiceModel.Dispatcher.ErrorHandlingReceiver.EndTryReceive(IAsyncResult result, RequestContext& requestContext)
at
System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult
result)
at
System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
at
System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
at System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.InputQueue`1.AsyncQueueReader.Set(Item item)
at System.ServiceModel.Channels.InputQueue`1.Shutdown(CommunicationObject
communicationObject)
at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnClosing()
at System.ServiceModel.Channels.CommunicationObject.Abort()
at System.ServiceModel.Dispatcher.DuplexChannelBinder.Abort()
at System.ServiceModel.Channels.ServiceChannel.OnAbort()
at System.ServiceModel.Channels.CommunicationObject.Abort()
at System.ServiceModel.Channels.ServiceChannel.OnInnerChannelFaulted(Object
sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.ServiceModel.Channels.CommunicationObject.OnFaulted()
at System.ServiceModel.Channels.ServerReliableDuplexSessionChannel.OnFaulted()
at System.ServiceModel.Channels.CommunicationObject.Fault()
at System.ServiceModel.Channels.CommunicationObject.Fault(Exception exception)
at
System.ServiceModel.Channels.ChannelReliableSession.OnLocalFault(Exception e,
Message faultMessage, RequestContext context)
at
System.ServiceModel.Channels.ChannelReliableSession.OnLocalFault(Exception e,
WsrmFault fault, RequestContext context)
at
System.ServiceModel.Channels.ChannelReliableSession.OnInactivityElapsed(Object state)
at System.ServiceModel.Channels.InterruptibleTimer.OnTimerElapsed()
at System.ServiceModel.Channels.InterruptibleTimer.OnTimerElapsed(Object
state)
at System.ServiceModel.Channels.IOThreadScheduler.WorkItem.Invoke()
at System.ServiceModel.Channels.IOThreadScheduler.ProcessCallbacks()
at System.ServiceModel.Channels.IOThreadScheduler.CompletionCallback(Object
state)
at
System.ServiceModel.Channels.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at
System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace>
<ExceptionString>System.ServiceModel.CommunicationException: The inactivity
timeout of (00:00:03) has been exceeded.</ExceptionString>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>
Any help would be much appreciated,
Regards,
Stephen.


