如何硬codeA默认WCF端点服务?codeA、WCF

2023-09-06 06:44:55 作者:想和我比懒?我懒得和你比

在自托管服务,我想使用在App.config中指定的端点(S),如果present,或默认端点指定code如果App.config中是空的。我怎样才能做到这一点?

In a self-hosted service, I'd like to use the endpoint(s) specified in App.config, if present, or a default endpoint specified in code if App.config is empty. How can I do this?

修改:澄清一下,这是在服务器上(服务)一侧使用的ServiceHost

Edit: to clarify, this is on the server (service) side using ServiceHost.

推荐答案

您可以配置部分如下:

var clientSection =  System.Configuration.ConfigurationManager.GetSection("system.serviceModel/client");

如果值为null,或者 clientSection.Endpoints 包含零元素则没有定义。

If value is null or if clientSection.Endpoints contains zero elements then it is not defined.