开发者

Proxy generation in WCF

In IDesign WCF coding standard it says : "Do not duplicate proxy code. If two or more clients use the same contract, factor the proxy to a separate class library." I would开发者_运维技巧 like to know what is the advantage of the above state ?


Apart from the general principle of DRY (don't repeat yourself), it avoids the potential confusion of having multiple types with the same names and members.

Of course if your two or more clients are totally independent (separate Visual Studio solutions), it's OK for each to have its own proxy.


To me it means that if you use a proxy method in more than one place, don't duplicate that code, instead move it to a separate class. For example, if you regenerate the proxy because an operation has been changed, you have to change your code everywhere you've used that operation. If that operation is only used in one spot, your code is much more maintainable.

This is also a good approach to encapsulate proxy usage and ensure the proxy is being used properly (channel is closed when finished, exceptions handled properly, channel aborted if exception caught, etc).

I recommend that if you are going to use the proxy approach that you do not use Visual Studio Add Service Reference to generate that proxy. If possible, consider using a ChannelFactory implementation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜