3

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

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
  • Hosting in a Windows Service _is_ self-hosting. There is no difference. – John Saunders Jun 28 '12 at 23:04
  • then what is the difference between these two: http://msdn.microsoft.com/en-us/library/ms733069.aspx and http://msdn.microsoft.com/en-us/library/ms731758.aspx ? – Saher Ahwal Jun 28 '12 at 23:11
  • Lower case service is not the same as upper case Service (to me). The first link is Windows Service (as in Admin Tools). The second link host in just an .exe. If this is going to be a Data Service then that is commonly hosted in IIS. Only a comment as I don't fully understand your question. – paparazzo Jun 28 '12 at 23:23
  • Well @Blam, my service eventually should be running as one of the services in services.msc it should have the OnStart and OnStop but it needs to be installed every time I make a change so it is not good for debugging. So I was wondering how one can use self hosting for debugging and then make it a service and implement the installer – Saher Ahwal Jun 29 '12 at 00:02
  • If that is the question then you got a good answer. – paparazzo Jun 29 '12 at 00:40

1 Answers1

4

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.

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
xtrem
  • 1,737
  • 12
  • 13
  • Thank You Moussa. I guess I will go with WCFServiceHost during development – Saher Ahwal Jun 28 '12 at 23:15
  • Good choice. I forgot to mention. In visual studio, if you create a "wcf service library" project type, it integrated WCFServiceHost for you so you can "start" the project. You can also setup this yourself in visual studio. Better yet, you can also launch the wcftestclient when your project starts. See: http://blogs.msdn.com/b/wcftoolsteamblog/archive/2010/01/04/tips-for-launching-wcf-test-client.aspx – xtrem Jun 28 '12 at 23:27