WCF 客户端配置 - 基地址? [英] WCF Client configuration - base address?
问题描述
我将一个 WCF 客户端连接到一组服务,所有服务都实现了相同的合同并且都在同一主机上.我希望有一种方法可以组合端点定义以减少配置混乱.我也宁愿不以编程方式进行 - 仅通过配置.现在,我的配置重复了很多次:
I'm connecting a WCF client to a group of services all implementing the same contract and all at the same host. I was hoping that there would be a way to combine the endpoint definitions to cut down on configuration clutter. I also would rather not do it programmaticly - just by configuration. Right now, my config has this repeated many times:
<endpoint address="http://hostname/ServiceA.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyBinding"
contract="ServiceReference.ISearchService" name="ServiceA">
</endpoint>
<endpoint address="http://hostname/ServiceB.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyBinding"
contract="ServiceReference.ISearchService" name="ServiceB">
</endpoint>
// continued for ServiceC, ServiceD, etc
对于服务器配置,有一些概念可用于此目的的baseAddressPrefixFilters" - 是否有用于客户端配置的内容?
For server configurations, there is some notion of "baseAddressPrefixFilters" that can be used for this purpose - is there anything for client configuration?
推荐答案
WCF 中有基地址的概念 - 不幸的是,它仅适用于自托管,例如在控制台应用程序或 NT 服务中托管您的服务.但是,这只适用于服务器端 - 客户端没有类似的东西.在客户端,您始终必须定义端点应连接到的完整、完整的服务地址.
There is the concept of a base address in WCF - unfortunately, that only works if you self-host, e.g. host your service in a console app or NT service. However, that only works on the server side - there's nothing similar on the client side. On the client side, you always have to define the complete, full service address your endpoint should connect to.
如果您在 IIS 中托管,您的服务地址由服务器名称、虚拟目录(可能还有其下的子目录)和用于在 IIS 中托管服务的 *.svc 文件的名称确定.这是一个固定的系统约定,您无法对其进行更改,不幸的是(.NET 4 将对此进行一些补救).
If you host in IIS, your service address is determined by the server name, the virtual directory (and possibly subdirectories under that) and the name of the *.svc file used to host the service in IIS. This is a fixed system convention and you cannot influence it, unfortunately (.NET 4 will bring some remedy to that).
这篇关于WCF 客户端配置 - 基地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!