Is it possible to extend the WorkflowServiceHost with custom endpoints in the same way endpoints are added to the ServiceHost class? For instance, an endpoint implementing the interface ICustomTracking with BasicHttpBinding.
I'm looking for a solution using code, not the config file.
Any idea?
Related
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 ServiceHostFactory implementation. A few things you'll need:
In web.config, set the attribute aspNetCompatibilityEnabled on the <system.serviceModel / serviceHostingEnvironment> element to true
Add a 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.
I have an IService.
It is implemented by Service1.
I bind IService to Service1 (im using ninject).
Can I have a .svc file that in the markup has...
Service="IService"
And tell wcf to somehow resolve that service and use it?
No, the .svc file is bound to the service type. What you can have is a route (if you use the ASP.NET Routes integration) where you, in code, resolve the IService binding to Service1 and add the route accordingly.
in the .svc file you can set Factory= to the class that you want to resolve the service. I have not tried setting Service to an interface. If it does not work you can use an abstract base class for your IOC.
I am trying to figure out how to get an handle on the endpoints of the service host and modify their identity. I have endpoints defined in the config file but want to modify the endpoints programmatically depending on the environment (ex:QA, UAT, Prod)
Service is hosted on IIS6 and I am using a servicehostfactory to provide my extended servicehost class to IIS.
I am using opening event to get an handle on the endpoints that are already defined from the config file but can't figure out how to modify their identity. Is that even possible? Are endpoints are immutable after they are created?
If I can't modify the endpoints then is the "Opening" event of the servicehost is the correct event to add a service endpoint?
ServiceHosts are not immutable until they are Opened. You can modify the description of an endpoint after calling AddServiceEndpoint.
When you say Opening event, do you mean you've subclassed ServiceHost and are overriding OnOpening? If so, that's a fine place to add endpoints.
Alternatively, if you're using your own ServiceHostFactory, you can just add your endpoint(s) after calling base.CreateServiceHost.
I know you can use multiple bindings, but if you implement a REST Service, must you use the webHttpBinding?
The webHttpBinding is what tells the WCF framework to communicate in a RESTful fashion - any other binding would define a different protocol. In your comment, you ask about wsHttpBinding - If you used that binding, you would not have a REST service, you'd have a SOAP web service.
You don't need to use directly WebHttpBinding. You can also use custom binding or your own binding but these bindings have to use HttpTransportBindingElement and WebMessageEncodingBindingElement. Both these binding elements are used by WebHttpBinding.
How to write a custom service host in WCF?
I want to have more control on service host.
Please guide me to write my custom service host?
You basically just need to derive from the base ServiceHost class. Anything else is totally up to you.
What do you want to improve upon? Where do you see things you need to do better or different than the standard ServiceHost class?
See these articles and blog post for samples and recipes on how to do it:
Of Hosts and Factories
Extending ServiceHost and the Service Model Layer
Custom ServiceHost Factory for WCF and IIS
Marc