何时在服务引用上使用 WCF ChannelFactory [英] When to use WCF ChannelFactory over service reference

查看:34
本文介绍了何时在服务引用上使用 WCF ChannelFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 WCF 教程,发现这些 tuts 指出我可以使用 mex 端点,以允许隐式地向客户端添加服务引用.我猜这允许 VS 在使用生成的 WSDL 文件时创建代理类?

I'm going through WCF tutorials and find that these tuts point me to make a mex endpoint available to allow for implicitly adding service references to clients. I guess this allows VS to create proxy classes when consuming the resultant WSDL file?

然而,我试图适应的代码库不使用隐式服务引用.相反,客户端可以访问 DuplexChannelFactory.通过显式 ChannelFactories 与隐式服务引用进行服务通信的好处是什么?

The codebase I'm trying to get comfortable on, however, does not use implicit service references. Instead clients have access to a DuplexChannelFactory. What are the benefits of service communication via explicit ChannelFactories vs implicit Service References?

这个问题在这里(如何重写 WCF 客户端以使用 ChannelFactory 而不是服务引用),其中提到一家公司选择 ChannelFactories 而不是服务引用,但没有提到原因.

This SO question here (How to re-write WCF client to use ChannelFactory instead of service reference) that mentions a company choosing ChannelFactories over service references but didn't mention why.

推荐答案

何时将 ChannelFactories 用于服务引用

When to use ChannelFactories over service references

总是使用 ChannelFactory,除非没有其他选择.我不能足够强烈地说明这一点.服务引用是

Always use ChannelFactory, except when there is no other option. I cannot state this strongly enough. Service references are

  • 复杂,
  • 不可预测,
  • 间接和
  • 经常 不是 工作,尤其是在更新时.
  • complex,
  • unpredictable,
  • indirect, and
  • often do not work, especially when updating.

您可能想要使用服务引用的唯一原因:

The only reasons you might want to use a service reference:

  1. 您没有对代码中的服务定义和合同类型的二进制访问权限.例如,您正在通过互联网调用一项公共服务,而该服务的开发者不可能将这些服务提供给您.
  2. 就是这样.这是唯一的原因.

如果您有权访问服务定义和合同类型,可能会争论说您应该使用服务引用,但它们是在一些超级程序集中定义的,还有一大堆您没有用的其他东西.但是,我觉得这是有问题的,因为在这种情况下,您只需重新创建服务定义和类型,并利用 WCF 对合同等效性的尊重.

It could be argued that you should use a service reference if you have access to the service definition and contract types, but they are defined inside some uber-assembly with a whole bunch of other stuff you have no use for. However, I find this questionable because in this instance you could just re-create the service definition and types and leverage WCF's respect for contract equivalence.

这篇关于何时在服务引用上使用 WCF ChannelFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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