简体   繁体   English

在app.config中指定默认的WCF端点

[英]Specify default WCF endpoint in app.config

When you add a service reference it creates the class "MyServiceClient" with a default constructor. 添加服务引用时,它将使用默认构造函数创建类“ MyServiceClient”。 If I use new MyServiceClient() I get an error: Could not find default endpoint... If I use new MyServiceClient("endpointName") it works. 如果我使用新的MyServiceClient(),则会出现错误:无法找到默认端点...如果我使用新的MyServiceClient(“ endpointName”),它将起作用。

I would like to specify a default endpoint in app/web.config which will get used when I use the default constructor. 我想在app / web.config中指定一个默认端点,当我使用默认构造函数时将使用它。 I know I can place that default name in *.settings and use it throughout my app, but just wondering if there is any built-in way to do it. 我知道我可以将默认名称放在* .settings中,并在我的应用程序中使用它,但是只是想知道是否有任何内置方法可以使用它。

If you have only a single endpoint in your client's app.config, then that one endpoint will be used. 如果客户端的app.config中只有一个端点,则将使用该端点。

If yuo have multiple endpoints in your client's app.config, you must define which one to use. 如果您的客户端的app.config中有多个端点,则必须定义要使用的端点。 There's no mechanism or feature in WCF do designate one as the "default" endpoint - and I haven't heard anything about WCF 4 adding any such feature, either. WCF中没有机制或功能会将一个指定为“默认”端点-我也没有听说过有关WCF 4添加任何此类功能的信息。

So if you want to have a default endpoint, then yes, you'll have to store the name of the endpoint in your app.config as well and programmatically retrieve that name before instantiating the endpoint. 因此,如果要使用默认终结点,则可以,您还必须将终结点的名称存储在app.config中,并在实例化终结点之前以编程方式检索该名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM