Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS WCF service hosting vs Windows Service

Tags:

c#

.net

iis

wcf

was

We developed a WCF service and we're looking to deploy it. Our clients will be using it with basicHttpBinding but our internal team will be using it with namedPipesBinding.

We are wondering if is it better to host it in IIS 7 or with a Windows Service. We ran some tests and we found out that when we're adding bindings in IIS, it doesn't update config file of our service. That means that we would need to maintain the configuration in two different places. It's not logical, right?

We also read on StackOverflow that the base address is ignored when a WCF service is host in IIS (see WCF service configuration file question regarding <baseAddresses>)

like image 536
esylvestre Avatar asked Oct 13 '09 14:10

esylvestre


1 Answers

Hosting in IIS has many pros and many cons.

Yes, IIS gives you on-demand loading - this can be a plus or a minus. When a request comes in, the ServiceHost is constructed, then the service class being hosted is instantiated, and the request is handled. Nothing needs to be running around the clock. But at the same time, this setup requires more time and effort every time a message comes in, and you as a programmer don't have much control over your service host, really.

And yes, with IIS, the virtual directory where the *.svc file resides defines your address - any base addresses or explicitly defined addresses in your config are disregarded. And without much effort, you cannot change the layout of the service addresses - they're always going to be http://servername/virtualdirectory/YourService.svc (including the .svc extension).

Self-hosting is often times faster, since your ServiceHost is already up and running - but it's up to you to make sure it really is up and running, there's no "on-demand" loading whenever a message comes in - either it's up and can service the request, or not. But you have a lot more control over the service host - when and how it's constructed etc., and you get to pick and define your service addresses as you see fit.

I personally would almost always choose to use self-hosting - in a console app for testing, in a NT service for production. To me, it just seems the more appropriate way to do it, and the more controlled way, too. You have to do more work - but you know exactly what you're doing.

Marc

like image 127
marc_s Avatar answered Sep 18 '22 05:09

marc_s