Tutorial :Using WebServiceHostFactory Pros & Cons


When hosting a WCF service on IIS you have an option of manually configuring the endpoint or declaratively by means of WebServiceHostFactory. It doesn't seem to be that difficult to manually create the endpoint so I figured I would ask.

  • What are the benefits of using WebServiceHostFactory?
  • Are there any performance implications to dynamically creating the endpoints?


Can you clarify : are you asking specifically about WebServiceHostFactory (emph: "Web")? Or just the difference between IIS hosting it vs starting your own server through code?

WebServiceHostFactory is new in .NET 3.5, and supports some of the newer AJAX/JSON stuff.

Actually, within IIS (using .svc), you are already using a ServiceHostFactory - simply the default one shipped with WCF. You can write your own factory if you want, and I've done this in the past to create a factory that only listens on https (I had an issues on a farm hosting multiple sites, where it couldn't identify the correct site for http, but https was fine - so I completely disabled http via the factory).

Performance shouldn't be any different as long as you don't go mad and listen on 200 end-points...

Generally, manually creating the server is used when you are hosting the server in (for example) a windows service. IIS is fine for some things, but app-pools get recycled, so aren't ideal for a server that needs to retain long-lived state. IIS has the advantage of being much easier to configure, especially with security (SSL etc) and compression.


I am definitely not an expert (yet), but cons that come to mind are:

  • you can only have one authentication method at a time (ie. not both Windows and anonymous) cf. WebServiceHostFactory and IIS authentication
  • Error handling is hard to do in a generic way (no Application_OnError, so you'll have to setup your endpoints manually after all)


  • effortless setup of REST services from scratch.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »