I have a interface-implementation pairs which I would like to convert them to services using WebServiceHost. However WebServiceHost requires a single instance or type that implements all the contracts. I thought about hooking into IInstanceProvider in WCF so that I can create specific instances based on the Message properties but it is not possible to create WebServiceHost without instance or type. Is this anyway possible or should I create multiple WebServiceHost instances for each of my interface-implementation pair? Also is there any penalty associated with creating large number (around hundred) of WebServiceHost instances on the same host and port but different URL?
-
See http://stackoverflow.com/questions/2142712/how-do-i-create-wcf-endpointbehaviors-in-code-rather-than-the-configuration – Jon Lindeheim May 13 '14 at 10:21
-
I read the post but not exactly what I am looking for. Since I have both contract and interfaces, I could generate one big object using reflection which will serve as singleton of the service but I am looking for a more elegant solution. – mll5 May 13 '14 at 11:24
1 Answers
Looking at the MSDN documentation for WebServiceHost
, I believe you will have to create multiple instances of WebServiceHost
Hosting n number of services on the same host/port with a different url does not have any impact on hosting. for instance you can host all your services using example below, and they should host correctly
http://localhost:1234/MyService1
http://localhost:1234/MyService2
http://localhost:1234/MyService3
...
http://localhost:1234/MyService100
The question here is going to be the scalability of your server. You are talking about having close to hundred WebServiceHost
. if all the services are light weight and does not create any large data objects, then you may not have any issues. but if each of these services creates/caches a lot of objects, you may run into memory issues. also if all the services are CPU intensive, then you might have to throttle the requests.
The only way to find that out is to load testing of your services.

- 1,257
- 13
- 28