Reputation: 65
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.
Upvotes: 2
Views: 455
Reputation: 87228
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 ServiceHostFactory
implementation. A few things you'll need:
aspNetCompatibilityEnabled
on the <system.serviceModel / serviceHostingEnvironment>
element to true
global.asax
/ global.asax.cs
file, and in the Application_Start
add a new ServiceRoute
to the ASP.NET RouteTable.Routes
collection. 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 Factory
attribute in the <%@ ServiceHost
directive.
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.
Upvotes: 2