Sometimes I see people
- hosting a WCF Service using Windows service and sometimes
- WCF Service hosted using IIS? What is the big difference?
In which scenarios we need to go with method 1) and in which scenarios we need to use method 2)
Sometimes I see people
In which scenarios we need to go with method 1) and in which scenarios we need to use method 2)
if you host your WCF in IIS, the app pool will automatically recyle if it detected problems in the application like if there are memory leaks or so. I think its one of the difference between hosting on IIS and win service. just my .02cents
In a Windows service the lifetime is controlled by the OS - you might therefore want to host your WCF service here if it performs heavy initial computation tasks or must perform things periodically. As @mcxiand mentions, in this case however you need to ensure that your WCF service is pretty robust.
You can host in IIS, if you can ensure that your service can startup quickly, and doesn't need to perform heavy computation either on startup or periodically.
You should read this for more details - http://msdn.microsoft.com/en-us/library/ms730158.aspx Relevant snippets from the article:
The scenario enabled by the managed Windows Service hosting option is that of a long-running WCF service hosted outside of IIS in a secure environment that is not message-activated. The lifetime of the service is controlled instead by the operating system.
The IIS hosting option is integrated with ASP.NET and uses the features these technologies offer, such as process recycling, idle shutdown, process health monitoring, and message-based activation. On the Windows XP and Windows Server 2003 operating systems, this is the preferred solution for hosting Web service applications that must be highly available and highly scalable.
For me, the big difference is control.
Take the service address for one:
When hosting in IIS, your service address is determined by your server name, the name of the virtual directory and the name and extension of the *.svc file for hosting your service:
http://yourserver/VirtualDir/YourService.svc
When hosting yourself, in a Windows Service, you can choose any address you want:
http://yourserver/Services/Public/MyService
Add to that all the problems with security setup and app pool recycling that IIS hosting has..... also: IIS hosting will create the ServiceHost
, and the Service
instance inside it, on demand, when a request comes in. Sounds great, but also incurs an overhead.
For me, any serious WCF hosting should be handled by using self-hosting (like in a Windows service).