Embedd_0913
Embedd_0913

Reputation: 16555

How to create Endpoints from app.config file in WCF?

I have a service which has one endpoint , I have defined this endpoint in app.config file. I want to know how can I create endpoints if I have app.config in program. Please give me an idea.

Upvotes: 0

Views: 2705

Answers (2)

marc_s
marc_s

Reputation: 754538

Do you have a generated proxy for your service? If so, just use the proxy client!

MyServiceClient proxy = new MyServiceClient();

Optionally, you can pass in a name for the configuration to use:

MyServiceClient proxy = new MyServiceClient("MyConfigName");

No need to do anything fancy.

If you haven't created a proxy (using "Add Service Reference" in Visual Studio or svcutil.exe on the command line), you'll need to add a reference to your assembly containing the service and data contracts, and then use

ChannelFactory<IMyService> factory = new ChannelFactory<IMyService>();
IMyService proxy = factory.CreateChannel( );

Again, for creating the channel factory, you can pass in a name of a configuration section, if you have multiple, to specify which one to use.

Also, to clarify - a client can only ever have one endpoint at any given time. The service might have multiple - but the client needs to make up its mind and connect to exactly one of those - you cannot have multiple endpoints in a client (as the title of your questions appears to imply).

Marc

Upvotes: 1

Calanus
Calanus

Reputation: 26277

If you are using Visual Studio use the WCF Service Configuration Editor (found under tools). Use this to open your config file or hosted service and then you can create your endpoints there. Any new endpoint configuration info will be saved into your app.config/web.config as appropriate

Upvotes: 0

Related Questions