在自托管服务中,我想使用 App.config 中指定的端点(如果存在),或者如果 App.config 为空,则使用代码中指定的默认端点。我怎样才能做到这一点?
Edit:澄清一下,这是在服务器(服务)端使用 ServiceHost。
一种方法是try
第一次尝试从配置文件加载,并将端点硬编码在catch
. EG:
MyServiceClient client = null;
try
{
client = new MyServiceClient();
}
catch (InvalidOperationException)
{
EndpointAddress defaultAddress = new EndpointAddress(...);
Binding defaultBinding = new Binding(...);
client = new MyServiceClient(defaultBinding, defaultAddress);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)