Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top