简体   繁体   English

在没有IIS的情况下部署WCF服务

[英]Deploying a WCF service without IIS

After a WCF service has been created, is there any way to deploy it without IIS? 创建WCF服务后,是否可以在没有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. 我创建的服务将仅在LAN内使用,并且我不希望主机只运行ASP.NET服务器来承载WCF服务。

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. 我需要能够执行此操作的另一个原因是,由于我将使用的DLL之一在ASP.NET中不能很好地工作。

You can host a WCF service in a Windows Service as well as IIS: 您可以在Windows服务和IIS中托管WCF服务:

You can host a WCF service in any EXE, not just a Windows Service. 您可以在任何EXE中托管WCF服务,而不仅仅是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. 顺便说一句,如果使用IIS进行部署,则可以免费获得IIS提供的所有其他功能,包括简单的Web部署,集成的安全性和ASP.NET事件模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM