Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity - Interception for a WCF service class?

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!

like image 529
Alexander Avatar asked Oct 09 '22 10:10

Alexander


2 Answers

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

like image 87
Kangkan Avatar answered Oct 13 '22 10:10

Kangkan


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

like image 30
Tomasz Jaskuλa Avatar answered Oct 13 '22 11:10

Tomasz Jaskuλa