5
votes

i have a client & server application which communicate using WCF. To add some custom session information to each WCF message header i wrapped the client WCF channel into a "ClientChannelProxy" class and used the Unity Interception extension to add my custom header information using aspects.

IUnityContainer container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<IClientService, ClientServiceProxy>();
container.Configure<Interception>().SetInterceptorFor<IClientService>(new
TransparentProxyInterceptor());

This works fine for the client since i can easly configure the unity container and interception using the code shown above.

But how to setup unity and interception on the server side? My WCF service is configured in a .SVC file, i don't have any possiblity to configure interception and getting my aspects executed.

<%@ ServiceHost Language="C#" Debug="true" Service="Test.ClientService" %>
<!-- How to configure Unity Interception for this WCF-Service ? -->

Would ne nice if anyone could help me getting it working. Thanks!

2
Do you want to add some handler before the invocation reaches the actual service class?Kangkan
Exaclty. On the client i add some principal information to the WCF message header. The server should read this header information and build a custom principal object bevore the actual service class is called.Alexander
I have added an answer looking at this.Kangkan

2 Answers

2
votes

You need to create an inspector/interceptor on the server side. You may refer to this post: WCF Parameter Validation with Interceptor and http://msdn.microsoft.com/en-us/library/ms751495.aspx

2
votes

You could enable your WCF service with DI on implementing your own InstanceProvider, ServiceHost, etc. with Unity. So you'll be able to plug your aspect.

Here's an exemple of how it could be achieved : http://initializecomponent.blogspot.com/2008/06/integrating-unity-with-wcf.html