VS2010 添加服务引用相对于直接 ClientBase 的优势 [英] VS2010 Advantages of Add Service Reference over direct ClientBase<>

查看:25
本文介绍了VS2010 添加服务引用相对于直接 ClientBase 的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在 VS2010 中使用添加服务引用"时会创建大量文件.其中一个文件是 Reference.cs,它为服务合同创建了一个 ClientBase.

I have noticed that when "Add Service Reference" is used in VS2010 then a ton of files are created. One of the files is Reference.cs which creates a ClientBase for the service contract.

因此,我想知道 VS 创建的大量额外文件是否有任何优势,或者我可以自己使用 ClientBase 并跳过添加服务引用"选项.

Thus, I was wondering is there any advantage to the slew of extra files VS creates or can I just use a ClientBase myself and skip the "Add Service Reference" option.

我应该注意,在我的情况下,双方都在我的控制之下.

I should note that in my case by sides are under my control.

推荐答案

以下是我个人观点的不同方法的优缺点概览:

Here's an overview of the pros and cons with the different approaches from my point of view:

优点

  • 入门所需的工作量最小
  • 能够在服务合同发生变化时快速更新代理
  • 无需维护自定义代码

缺点

  • 使消费者难以使用任何流行的 .NET 隔离框架进行单元测试,例如 Rhino MocksMoq,由于与 WCF 基础结构的高耦合通过 ClientBase
  • 创建了不必要的额外文件
  • Makes consumers difficult to unit test with any of the popular isolation frameworks for .NET, such as Rhino Mocks or Moq, due to high coupling with the WCF infrastructure through the ClientBase<TChannel> class
  • Unnecessary extra files are created

优点

缺点

  • 需要一些初步的努力才能开始
  • 一些需要维护的自定义代码

总结一下,使用代理在使用 WCF 服务时可以减少摩擦同时放弃一些控制和可测试性.使用Channel API 需要更多代码,以换取更高程度的灵活性,这会派上用场,特别是如果您想将组件与它们通信的 WCF 服务分开进行单元测试.

To summarize using proxies provides less friction when consuming WCF services while giving up some control and testability. Using the Channel API requires more code in exchange for a higher degree of flexibility, which comes in handy especially if you want to unit test components separately from the WCF services they communicate with.

相关资源:

这篇关于VS2010 添加服务引用相对于直接 ClientBase 的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆