How To Define An Endpoint Programmatically In WCF ? | WCF Interview Question

, ,
ServiceHost host = new ServiceHost(typeof(EmployeeReservations));

host.AddEndpoint(typeof(EmployeeReservations), new BasicHttpBinding(), "http://www.google.com/employee/emp.svc");

EmployeeReservations is the name of the contract.
http://www.google.com/employee/emp.svc is the address of the web service.

Even though defining endpoints programmatically is possible, the most common approach today is to use a configuration file associated with the service. Endpoint definitions embedded in code are difficult to change when a service is deployed, yet some endpoint characteristics, such as the address, are very likely to differ in different deployments. Defining endpoints in config files makes them easier to change, since changes don?t require modifying and recompiling the source code for the service class.