开发者

Specify default WCF endpoint in app.config

开发者 https://www.devze.com 2022-12-26 08:00 出处:网络
When you add a service reference it creates the class \"MyServiceClient\" with a default constructor.If I use new MyServiceClient() I get an error: Could not find default endpoint...If I use new MySer

When you add a service reference it creates the class "MyServiceClient" with a default constructor. If I use new MyServiceClient() I get an error: Could not find default endpoint... If I use new MyServiceClient("endpointName") it works.

I would like to specify a default endpoint in app/web.config which will get used when I use the def开发者_运维问答ault constructor. 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.


If you have only a single endpoint in your client's app.config, then that one endpoint will be used.

If yuo have multiple endpoints in your client's app.config, you must define which one to use. 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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消