I have a WCF service which programmatically creates its endpoints rather than using a config file – I’m looking into this as our field engineers are prone to break XML easily and we may use different types of binding in different scenarios.
This works well in self-hosted environments (console app, windows app) and as a Windows Service.
Can I do this with a service in IIS or do I have to provide a .SVC file for each endpoint ?
Also will the endpoint address from the client end have to include the .SVC extension ?
This is not a service intended to be used by third parties, only by our client components. We may expose parts of our API later but not initially.
If you’re using .NET Framework 4.0 (and later), you can use the ASP.NET routing integration to define a service using a custom
ServiceHostFactoryimplementation. A few things you’ll need:aspNetCompatibilityEnabledon the<system.serviceModel / serviceHostingEnvironment>element totrueglobal.asax/global.asax.csfile, and in theApplication_Startadd a newServiceRouteto the ASP.NETRouteTable.Routescollection. The service route requres you to define a new service host factory, where you can define your endpoints programmatically.With that you’ll be able to have endpoints without the “.svc” in their addresses. You can also use the service host factory without using routes, by creating a .svc file for each service (not endpoint), and using the
Factoryattribute in the<%@ ServiceHostdirective.For more information about service host factories, check the post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/06/14/wcf-extensibility-servicehostfactory.aspx.