Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does someone have an example of why I would self-host a WCF service

Tags:

.net

asp.net

wcf

I guess my mind is so engaged in IIS and web applications that I can't think of a reason to go through the trouble of using a self-hosted WCF service. I have always had the availability of IIS so creating a self-hosted WCF service seems like more work than I would want to do. Why would I want to do this?

like image 335
RJ. Avatar asked May 24 '10 18:05

RJ.


2 Answers

Lots of points:

  • no need for IIS - this can be a great plus on certain servers
  • you get to completely define the service addresses - with IIS, they're dictated by server name, name of the virtual directory, plus the name and extension of the SVC file (e.g. http://server/virtualdir/yourservice.svc, while with self-hosting you can use http://Server:7171/Services/MegaService or whatever you like)
  • no risk of running into issues related to app pools being recycled (this can be lessened significantly by using separate dedicated app pools for your WCF services)
  • ability to stop and start the NT services, thus e.g. taking those services offline for a bit (less easily done with IIS, I believe)
  • more control over the creation and the options for the ServiceHost
  • support for all protocols out of the box - netTcpBinding etc. requires additional steps (which might be forgotten) on IIS7 and are impossible to do on IIS6
like image 60
marc_s Avatar answered Oct 23 '22 11:10

marc_s


It's all about how you want to use WCF. Not always the logic you want exposed as a service needs to/can be hosted in IIS. For example:

  • you are using WCF to build a P2P channel between multiple instances of your client app on the local network.
  • you are building a local WCF service that is deployed on a client SKU, where IIS is not installed by default
  • you want complete control of your endpoint addresses
  • you want to use net.tcp or net.pipe channels
  • you want full control over the lifetime and instance model of your service
  • you want the service to be running as the interactive user (impersonation is not always the answer)
like image 21
Franci Penov Avatar answered Oct 23 '22 09:10

Franci Penov