WCF 4: AddDefaultEndpoints

Here is another little goodie we have which will help in reducing configuration. You can use the ServiceHostBase.AddDefaultEndpoints which will pretty much probe your service implementation for contracts and expose them as shown below. Notice that I don’t need to specify anything more than the base address and the type of the service and I have actually commented out the call to the API. You can find more details about the simplified configuration here.


ServiceHost host = new ServiceHost(typeof(Service1),                new Uri("net.tcp://localhost:8080/"),                new Uri("http://localhost:8081/"));//host.AddDefaultEndpoints();host.Open();



*NOTE: You will get these defaults only if you do not explicitly add an endpoint.