问题
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:
- 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.
- 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