Question

I am currently working on a project that should be implemented as a WCF service (of course with a client application as well).

The project also needs to use Entity Framework (Code-First approach) as the ORM layer between the service and the DB.

Eventually, this service should be hosted as Windows Service. I was wondering at start if I could just use self-hosting and then switch to Windows Service hosting. How easy is it to switch through visual studio without manually copying files and code.

Thanks

Was it helpful?

Solution

Create a "XXXServiceLibrary" project (dll) that contains the services and no hosting logic. Implement your services and all their logic here.

While you are focusing on the services only, and not yet caring about hosting them, you may use one of the below hosts:

  • WCFServiceHost (http://msdn.microsoft.com/en-us/library/bb552363.aspx)
  • IIS/WAS (create a web project XXXIISServiceHost, and enter the necessary configuration in the web.config for hosting your services. You may also use .svc files for simplicity)
  • A Simple Console App XXXConsoleServieHost, and manually write your self hosting logic. But if your service do not require any special hosting logic, use one of the two first options.

When you're done developing and unit testing your services, then create your XXXWinSvcServiceHost project (Windows Service), and implement your hosting logic in it.

You got it. Separate your service library from its hosting project. And yes, it is very easy and straight forward to move from one host to the other. In most cases, you don't need to repeat the configuration work; just copy it over.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top