I was intrigued by this forum discussion about attaching context to the lifetime of a service operation.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=733385&SiteID=1
Basically, the question is how to create the equivalent of the HttpContext we have with ASP.NET requests. The OperationContext is the closest we have to a request lifecycle, and it turns out you can add to the context by implementing IExtension<OperationContext>.
Attached is a sample: CustomContext.zip (91.4 KB)
Here's how it works:
[ApplicationRequestContext]public class HelloIndigoService : IHelloIndigoService
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase){ foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers) { foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints) { endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this); } } }
OperationContext.Current.Extensions.Add(new ApplicationRequestContext());
OperationContext.Current.Extensions.Remove(ApplicationRequestContext.Current);
public static ApplicationRequestContext Current{ get {return OperationContext.Current.Extensions.Find<ApplicationRequestContext>();}}
Many thanks to Scott Mason on the WCF team for helping me find the right hooks for this purpose...
Remember Me
Designed by NUKEATION STUDIOS