Configure WCF Service Endpoint dynamically(Part-15)

We can configure WCF service endpoint in 2 ways.

  • Declare in configuration file
  • Dynamically in code

Declare in configuration file
You can declare the endpoints declaratively in WCF service. we will take example of Hello Service.In app.config, you will see the end point.

Also you will have a service behavior where you will be defining the service metadata exchange.

Then if you will run the service it would work fine.
Dynamically in code:
Lets see how we need to define the endpoints dynamically in code.

  • Delete the endpoint and service behaviors from configuration file.
  • Then in HelloServiceHost, we need to add the endpoints before opening the host in program.cs
  • You need to use System.ServiceModel.Description namespace for using ServiceMetadataBehavior.

Now if you will run the client, it will work fine.

© 2015, www.techkatak.com. All rights reserved.