WCF 自动生成的代理与自定义代理:走哪条路、何时以及为什么?
在过去的两年里,我一直在 TCP/IP 协议的通信层使用 WCF 在 c# 3.5 中开发分布式应用程序;到目前为止,我一直在使用集成的添加服务引用...在客户端生成服务代理,但我也知道使用通道工厂创建通信通道(从而访问服务契约方法)是一种可行的方法。
问题非常简单(请论证答案):
- 哪些是优点和缺点?这两种方法的缺点是什么?
- 在大多数情况下应该首选“自动”生成方法吗?如果是,为什么?
- 在哪种情况下(如果有)“自定义”方法是合理/需要的?
(请告诉我是否需要更多上下文来回答)
In the last 2 years I've been developing a distributed application in c# 3.5 using WCF at communication tier on TCP/IP protocol; so far I've been using the integrated Add Service Reference... to generate service proxies on the client side, but I also know that using channel factories to create a communication channel (thus accessing service contract methods) is a viable approach.
The questions are pretty straightforward (please argument the answers):
- Which are the pros & cons of either approach?
- Should the "automatic" generation method be preferred in most contexts, and if so, why?
- Under wich circustances (if any) is the "custom" approach justified/needed?
(please tell me if more contextualization is needed to answer)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,使用自定义代理的原因之一是能够在客户端和服务器上使用相同的接口[类型]和域类型。自动生成会创建相当多的类,这将不可避免地增加程序集的大小,因此,如果您正在构建下载时间至关重要的 silverlight 应用程序,或者如果您有很大的内存限制,那么通道工厂可能是最佳选择。
我也喜欢通道工厂的干燥性,因为我通常都有域对象,为什么要再次生成它们呢?特别是如果我里面有一堆商业逻辑的话。当然,这实际上仅适用于 wcf 到 wcf 通信,如果您正在与任何其他服务通信,您会希望生成域对象
(我还假设域类型和接口位于它们自己的中)程序集,与实际的后端持久性代码分开)
For me the one reason to use custom proxies is to be able to use the same interface[type] and domain types on both the client and the server. The automatic generation creates quite a few classes that will inevitably increase the size of your assembly, so if you're building a silverlight app where download time is critical or if you have a hefty memory constraint, channel factory might be the way to go.
I also like the DRY-ness of channel factory, since i typically have my domain objects anyway, why generate them again? Especially if i have a bunch of buisness logic in them. Ofcourse, that is really only applicable to wcf-to-wcf communication, if you're talking to any other service, you'd want to have the domain objects generated
(Im also assuming here that the domain types and interfaces are in their own assembly, separate from the actual back-end persistance code)