3

我正在尝试创建一个 Windows 服务应用程序,我可以像在 WPF 和 Silverlight 中那样在其中添加模块。我就是这样扔的:

public static class Program
{
    public static string CurrentAppPath { get; set; }

    static void Main()
    {
        Program.CurrentAppPath = Path.GetDirectoryName(
             System.Reflection.Assembly.GetEntryAssembly().Location);

        ShellBootstrapper bootstrapper = new ShellBootstrapper();
        bootstrapper.Run();
    }    
}

对于 ShellBootstrapper 类:

class ShellBootstrapper : UnityBootstrapper
{
    protected override IModuleCatalog CreateModuleCatalog()
    {
        DirectoryModuleCatalog directoryCatalog = 
          new DirectoryModuleCatalog() { ModulePath = Program.CurrentAppPath };
        return directoryCatalog;
    }

    protected override System.Windows.DependencyObject CreateShell()
    {
        return null;
    }        

    public override void Run(bool runWithDefaultConfiguration)
    {
        base.Run(runWithDefaultConfiguration);

        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new MyService(logger)
        };
        ServiceBase.Run(ServicesToRun);
    }        
}

那里有样品吗?

4

1 回答 1

1

锁定于此。你可以下载那里的样本,如图所示

下载并安装 prism(v4) 后,在根目录中有名为stock trader. 这就是你需要的!(运行桌面版)。在模块部分中,您可以找到名为service.

这很简单,你可以在这里调用这些方法中的 Wcf-service。(你也可以使用 wcf 方法作为 async-service )

于 2011-05-15T06:01:49.173 回答