Friday, October 8, 2010

Wcf self hosting - also in VS 2010


A while ago I published a Wcf self hosting template project for visual studio 2008.
The same template also works for VS 2010: just put this under

"%My Documents%\Visual Studio 2008\Templates\ProjectTemplates\Visual C#\WCF"

and the new template is under the C# / Wcf node:

Enjoy :)


What's next? get this blog rss updates or register for mail updates!


Olivier said...

Thanks Yaron. Always useful posts!
What I found out to be very useful in case of self hosting is the capability to run the same code either as a console app or as a windows service. This allows for example to be able to debug without having to install the windows service and attach visual studio for debugging.
For that, some code is needed in the Main() of the ServiceBase class:
#if (!DEBUG)
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new AdminConsoleWindowsService() };
// Debug code: this allows the process to run as a non-service.
// It will kick off the service start point, but never kill it.
// Shut down the debugger to exit
AdminConsoleWindowsService service = new AdminConsoleWindowsService();
// Put a breakpoint on the following line to always catch
// your service when it has finished its work

This is from Lee Humphries:


Yaron Naveh (MVP) said...


This is a great idea. Usually I would create a service library and then have a separate executable to host it, but this is better.