views:

210

answers:

1

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

A: 

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.

marc_s
I read something that hinted at having one endpoint, but I hadn't tried it out. I prefer having only the name of the endpoint to configure rather than having to remove/create whole sections when I want to change it. Thanks!
Nelson