When to use WCF ChannelFactory over service reference [duplicate]

我只是一个虾纸丫 提交于 2019-12-08 02:56:31

问题


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?

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?

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.


回答1:


When to use ChannelFactories over service references

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. You don't have binary access to the service definition and contract types in code. For example, you're calling a public service across the internet and there's no way the developers of the service are going to give them to you.
  2. That's it. That's the only reason.

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.



来源:https://stackoverflow.com/questions/41937592/when-to-use-wcf-channelfactory-over-service-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!