When to use a proxy?
If you have a service that you know is going to be used by several applications or is generic enough to be used in several places, you’ll want to use the proxy classes.
When to use ChannelFactory?
ChannelFactory class is used to construct a channel between the client and the service without the need of a proxy. In some cases, you may have a service that is tightly bound to the client application. In such a case, you can reference the Interface DLL directly and use ChannelFactory to call your methods using that.
When to use a ChannelFactory over Proxy class
Use of DLL is helpful if the client code is under you control and
- You’d like to share more than just the service contract with the client such as some utility methods associated with entities.
- Make the client & the service code more tightly bounded.
- If you know that your entities will not change much and the client code is less, then a DLL would work better than a proxy.
Proxies have several restrictions such as:
- They need to have gets and sets
- Contractors can’t be exposed
- Methods other than the service contract cannot be exposed
- Repetition of code
- Every time that we add/modify a service contract/data contract/message contract we need to re-generate the proxy for the client.
So if you are designing a connected system and using WCF for that, then you can use a shared dll instead of a proxy.
Remember: sharing more than just the service contract with the client goes against the SOA fundamental – loose coupling between the consumers and services.
No comments:
Post a Comment