WCF Intercommunication using Unity

Dec 13, 2011 at 4:57 PM
Edited Dec 13, 2011 at 4:59 PM

 

Hello EntLib Team,
I need your help for a sample solution that shows 2 WCF services communicate to each other in the same project Server, or just one WCF service
that send some data to the other WCF service.
I want to use Unity if it make it easy that's why I posted this issue :
Thank you in advance,
Best regards,

Maher Jendoubi

Dec 14, 2011 at 5:23 AM

Maher,

If you have generated proxy classes (or proxies that you manually created) for your services and you want to use those classes then it's just a matter of resolving them through the container:

IUnityContainer container = new UnityContainer();
container.RegisterType<IMyWcfService, MyWcfService>();

IMyWcfService client = container.Resolve<IMyWcfService>();
client.DoSomething();

A cleaner way that avoids the use of proxies is to wrap the interface in a ChannelFactory:

IUnityContainer container = new UnityContainer();

container.RegisterType<IMyWcfService>(
    new InjectionFactory(
        c => new ChannelFactory<IMyWcfService>(endpointConfigurationName)
                    .CreateChannel()));

// ...

IMyWcfService client = container.Resolve<IMyWcfService>();
client.DoSomething();

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com