Search code examples
wcfchannelfactory

Confusion about WCF Channels


I am confused about the Proxy and Channels. According to my reading, WCF client is using a proxy which pass the message through a chain of channels. Every Channel is responsible of certain task, for example one channel is encoding the message and another Channel is encrypting it.

My confusion begins when I saw the following code

  • When proxy.MyMethod() is called, it actually called the whole chain of channels?

  • The author used method called CreateChannel and named the identifier proxy. So in WCF architecture Proxy is just a spacial high level channel, it is not a stand alone architecture element?

    Binding binding = new NetTcpBinding();  
    EndpointAddress address = new EndpointAddress("net.tcp://localhost:8000");  
    IMyContract proxy = ChannelFactory<IMyContract>.CreateChannel(binding,address);  
    using(proxy as IDisposable)  
    {  
        proxy.MyMethod();  
    }  
    

Solution

  • Yes, I think you described this accurately. WCF has this concept of "channels", which developers tend to configure in the web.config and not write C# code around.

    These are described in the Channel Model Overview.

    When you call ChannelFactory.CreateChannel(binding,address); the framework looks at your configuration and creates all these channels for you as one object. So yes, the proxy is like a stack of channels.

    From your end you interact with it as one object. The framework deals with the implementation of separate channels. It is still nice to understand that you are going through these layers so that you can configure them properly.