【问题标题】:Installing and Running WCF Service inside a Windows Service在 Windows 服务中安装和运行 WCF 服务
【发布时间】:2013-04-16 18:14:15
【问题描述】:

我不是 C# 或 .NET 专家。但是,我必须使用它...

我正在运行InstallUtil.exe MyService.exe 来安装本质上运行 WCF 服务的 Windows 服务。我已经定义了 WFC 接口并实现了它。下面是界面。

[ServiceContract(Namespace = "http://WCFService", Name = "WCFService")]
public interface IWCFService
{
    [OperationContract]
    User Login(string userName, string password);

    [OperationContract]
    List<Project> GetProjects(Guid userGuid);

    [OperationContract]
    List<Stylesheet> GetStylesheets(Guid projectGuid);

}

我还定义了一个 Windows 服务如下:

public partial class Service: ServiceBase
{
    public FlatWsdlServiceHost m_fwsh = null; // extends ServiceHost

    public DesignerService()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {

        this.EventLog.WriteEntry("OnStart Successfull", EventLogEntryType.Information);

        if (m_fwsh != null)
        {
            m_fwsh.Close();
        }

        // Create a ServiceHost for the EventWebService type and 
        // provide the base address.
        Uri localUri= new Uri("http://localhost:7777/");
        m_fwsh = new FlatWsdlServiceHost(typeof(WCFService), localUri);

        // Open the ServiceHostBase to create listeners and start 
        // listening for messages.
        m_fwsh.Open();
    }

    protected override void OnStop()
    {
        //base.OnStop();

        if (m_fwsh != null)
        {
            m_fwsh.Close();
            m_fwsh = null;
        }
    }

    protected override void OnPause()
    {
        base.OnPause();
    }
}

当我运行InstallUtil.exe MyService.exe 时,日志显示:

Installing assembly 'MyService.exe'.
Affected parameters are:
   logtoconsole = 
   logfile = MyService.InstallLog
   assemblypath = MyService.exe
No public installers with the RunInstallerAttribute.Yes attribute could be found in the MyService.exe assembly.
Committing assembly 'MyService.exe'.
Affected parameters are:
   logtoconsole = 
   logfile = MyService.InstallLog
   assemblypath = MyService.exe
No public installers with the RunInstallerAttribute.Yes attribute could be found in the MyService.exe assembly.
Remove InstallState file because there are no installers.

另外,我确实有一个 ProjectInstaller.cs,它初始化 serviceInstaller1 和 serviceProcessInstaller1。在添加 WCF 服务之前,Windows 服务安装良好并将“OnStart Successl”消息写入 Windows 日志。

非常感谢任何帮助或建议。

【问题讨论】:

  • 添加安装程序时,是否右键单击服务设计界面并选择“添加安装程序”?
  • 有关添加安装程序的更多详细信息,请参阅此处的“创建 Windows 服务项目”部分:support.microsoft.com/kb/317421
  • @PeterRitchie 是的,但是我做到了,我在添加 WCF 服务之前添加了安装程序。这会导致问题吗?
  • 不,不应该。实际上,Windows 服务的安装与 WCF 无关——它们之间没有依赖关系。
  • @drunkenRabbit +1 evgenyl 的评论。这不应该导致任何基础安装问题

标签: c# .net wcf windows-services


【解决方案1】:

你需要这样的课程:

// Provide the ProjectInstaller class which allows 
// the service to be installed by the Installutil.exe tool
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
    private ServiceProcessInstaller process;
    private ServiceInstaller service;

    public ProjectInstaller()
    {
        process = new ServiceProcessInstaller();
        process.Account = ServiceAccount.LocalSystem;
        service = new ServiceInstaller();
        service.ServiceName = "WCFWindowsServiceSample";
        Installers.Add(process);
        Installers.Add(service);
    }
}

完整教程在MSDN

【讨论】:

  • 你是公开的并且有属性 RunInstaller 并且它在 MyService.exe 中吗?该错误清楚地表明缺少此类:“在 MyService.exe 程序集中找不到具有 RunInstallerAttribute.Yes 属性的公共安装程序。”
  • 不知道是什么问题。但是我删除并重新创建了服务的安装程序,并且它工作......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-28
相关资源
最近更新 更多