Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net WCF客户端配置-将多个服务重定向到另一台主机_.net_Wcf_Wcf Client_Endpoint_Base Address - Fatal编程技术网

.net WCF客户端配置-将多个服务重定向到另一台主机

.net WCF客户端配置-将多个服务重定向到另一台主机,.net,wcf,wcf-client,endpoint,base-address,.net,Wcf,Wcf Client,Endpoint,Base Address,现在,我的客户端中有多个服务,如下所示: <endpoint address="http://hostname/ServiceA.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_MyBinding" contract="ServiceReference.ISearchService" name="ServiceA"> </endpoint> <en

现在,我的客户端中有多个服务,如下所示:

<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>

还有很多

此web.config使宿主环境之间的切换变得困难且容易出错,因为您需要替换所有和每个端点地址上的“主机名”

我想以某种方式添加一个环境应用程序设置或其他东西,让我指定一个主机,并将端点解析为
http://{hostA}/ServiceX.svc


我是否需要通过编程实现一些神奇的功能,或者我可以单独从配置中实现这一功能?

您需要通过代码实现这一功能-配置中没有“通配符”,您可以在
部分中使用它作为基址。但是,您可以在配置中使用一些占位符(如“localhost”),在代码中首先加载配置,然后使用实际值更新服务器名称(也可以存储在配置中,例如,在AppSettings或其他地方)

var-factory=newchannelfactory(“ServiceA”);
factory.Endpoint.Address=ReplaceServerName(factory.Endpoint.Address);
var proxy=factory.CreateChannel();
...

可能相关:@marc\s您能提供一个示例或链接吗?我的服务是在中声明的,我看到的所有示例都将基址放在标记中对不起,我错过了在客户端的部分-基址仅在服务器端工作,不幸的是:-(简单的ctrl+h(查找和替换):p如果你不需要在应用程序上线时更改它,你可以为你做一些简单的工作。+1是的,我想这将是客户端唯一可以管理一半的解决方案-太糟糕了,客户端没有“基址”概念。。。
var factory = new ChannelFactory<ISearchService>("ServiceA");
factory.Endpoint.Address = ReplaceServerName(factory.Endpoint.Address);
var proxy = factory.CreateChannel();
...