generic service host factory for multiple services (and their multiple service contracts)


 

1 public class WebEnabledServiceHostFactory : ServiceHostFactory 2 { 3 4 private static readonly object locker = new object(); 5 6 private static Dictionary serviceLookup = new Dictionary(); 7 8 static WebEnabledServiceHostFactory() 9 { 10 lock (locker){ 11 serviceLookup.Add(typeof(ICalculatorService), typeof(CalculatorService)); 12 } 13 } 14 15 protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) 16 { 17 ServiceHost host = new ServiceHost(serviceLookup[serviceType], baseAddresses); 18 19 ServiceEndpoint endpoint = host.AddServiceEndpoint(serviceType, new WebHttpBinding(), "web"); 20 21 endpoint.EndpointBehaviors.Add(new WebHttpBehavior()); 22 23 ServiceMetadataBehavior smb = new ServiceMetadataBehavior { HttpGetEnabled = true }; 24 host.Description.Behaviors.Add(smb); 25 26 return host; 27 } 28 29 } 30

from http://toreaurstad.blogspot.com/2013/05/creating-webenabled-service-via.html

Advertisements

About home_pw@msn.com

Computer Programmer who often does network administration with focus on security servers. Very strong in Microsoft Azure cloud!
This entry was posted in wcf. Bookmark the permalink.