rafale
rafale

Reputation: 1735

Deploying a WCF service without IIS

After a WCF service has been created, is there any way to deploy it without IIS? The service I've created will only be used within the LAN, and I'd rather not have the host run an ASP.NET server just to host the WCF service.

The other reason I need to be able to do this is because one of the DLLs I'll be using doesn't really work well with ASP.NET.

Upvotes: 0

Views: 2275

Answers (2)

Roy Dictus
Roy Dictus

Reputation: 33139

You can host a WCF service in any EXE, not just a Windows Service. You have to write some code to host, but it's trivial:

using System;
using System.ServiceModel;
using System.ServiceProcess;

namespace MyService.Hosts
{
    public partial class MyWindowsService : ServiceBase
    {
        ServiceHost host;

        public MyWindowsService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            Type serviceType = typeof(MyWcfService);
            host = new ServiceHost(serviceType);
            host.Open();
        }

        protected override void OnStop()
        {
            if(host != null)
               host.Close();
        }
    }
}

BTW, if you deploy using IIS, you get all the extras that IIS offers for free, including easy Web deployment, integrated security, and the ASP.NET event model.

Upvotes: 3

Mitch Wheat
Mitch Wheat

Reputation: 300549

You can host a WCF service in a Windows Service as well as IIS:

Upvotes: 6

Related Questions