Last post Oct 19, 2009 06:48 AM by dvd.ribeiro
Oct 14, 2009 07:06 AM|dvd.ribeiro|LINK
Hi, I have a WCF simple service (calculator), and I created the code for it as a Windows Service. It has the interface, the service, and a windowsservice.cs class like this:
public class CalculatorWindowsService : ServiceBase
public ServiceHost serviceHost = null;
// Name the Windows Service
ServiceName = "WCFWindowsCalculatorService";
public static void Main()
// Start the Windows service.
protected override void OnStart(string args)
if (serviceHost != null)
// Create a ServiceHost for the CalculatorService type and
// provide the base address.
serviceHost = new ServiceHost(typeof(CalculatorService));
// Open the ServiceHostBase to create listeners and start
// listening for messages.
protected override void OnStop()
serviceHost = null;
The thing is, that this code is mainly made for Windows Services.
How do I also make code to use this same service both as Windows service and as Web Service?
I'm new at WCF, trying to figure out some differences in technical terms...
Thank you a lot!
Oct 14, 2009 12:14 PM|randallt|LINK
In WCF, a service can be hosted in a number of different ways: in IIS, as aWindows service, in console apps or even in Windows Forms and WPF apps. The service contract and implementation code can all be re-used, only the hosting code changes. The code
you have posted above is simply for hosting the service--so it won't be useful to you when you try to create a web service--but the CalculatorService code itself can still be reused. For how to host a WCF service in IIS, see:
Also note that this isn't actually a WCF forum, it focuses on the REST Starter Kit.
General WCF questions are better suited for the WCF forum on MSDN, here's the link:
Oct 19, 2009 06:48 AM|dvd.ribeiro|LINK
Thank you a lot.