ChannelFactory versus Proxy generation
When creating a WCF Client we have two possibilities:
The well known option is to create a proxy using svcutil.exe, this implies having the proxy class itself and the corresponding changes to the application configuration file.
But we have another option, we could use the ChannelFactory class to construct a channel between the client and the service without the need of a proxy.
Suppose that we have the following contract:
This is the codesnippet for the channel creation on the client:
This has in my opinion a couple of benefits:
- We dont need to generate the proxy class and configure the client.
- In a development enviroment everytime that we add/modify a service contract/data contract/message contract we need to re-generate the proxy for the client. This could save time everytime that we need to run our tests :)
Please check the documentation for more information.
Pablo