servicestack 什么';在windows服务中托管ServiceStack的正确方法是什么?,servicestack,topshelf,servicestack,Topshelf" /> servicestack 什么';在windows服务中托管ServiceStack的正确方法是什么?,servicestack,topshelf,servicestack,Topshelf" />

servicestack 什么';在windows服务中托管ServiceStack的正确方法是什么?

servicestack 什么';在windows服务中托管ServiceStack的正确方法是什么?,servicestack,topshelf,servicestack,Topshelf,我不使用HTTP功能,只使用MQMessaging,因此设置我的应用程序主机并侦听端口不是一项要求(目前)。我确实想要所有的管道,尽管它是默认的,例如IoC ect 这可能吗?仅供参考,我现在正在使用Topshelf引导服务,它似乎工作正常,我不需要监听HTTP请求 谢谢,, 斯蒂芬 公共类程序 { 公共静态void Main() { HostFactory.Run(x=> { x、 服务(s=> { s、 ConstructUsing(name=>newapphost()); s、 开始时(a

我不使用HTTP功能,只使用MQMessaging,因此设置我的应用程序主机并侦听端口不是一项要求(目前)。我确实想要所有的管道,尽管它是默认的,例如IoC ect

这可能吗?仅供参考,我现在正在使用Topshelf引导服务,它似乎工作正常,我不需要监听HTTP请求

谢谢,, 斯蒂芬

公共类程序
{
公共静态void Main()
{
HostFactory.Run(x=>
{
x、 服务(s=>
{
s、 ConstructUsing(name=>newapphost());
s、 开始时(ah=>
{
啊,Init();
啊。开始(“http://*:8088/”;
“主消息处理器正在侦听http://localhost:8088 “.Print();
});              
s、 停止时(ah=>ah.Stop());
});
x、 RunAsLocalSystem();
x、 SetDescription(“处理Leads应用程序的所有消息”);
x、 SetDisplayName(“Leads消息处理器”);
x、 SetServiceName(“LOLeadsProcessor”);
});
}
}
公共类AppHost:AppSelfHostBase
{
公共AppHost()
:base(“LO.Leads.Processor”,类型为(HelloService.Assembly)
{
//伐木
LogManager.LogFactory=new NLogFactory();
}
公共覆盖无效配置(容器)
{
//兔子
Register(c=>newrabbitmqserver(“cdev-9010.example.com”、“test”、“test”)
{
AutoReconnect=true,
DisablePriorityQueues=true,
}); 
RabbitMqServer mqServer=(RabbitMqServer)container.Resolve();
mqServer.RegisterHandler(m=>
{
返回新的HelloIntroResponse{Result=“Hello,{0}!”.Fmt(m.GetBody().Name)};
});
mqServer.Start();
}
}

在Windows服务中托管ServiceStack与任何其他.NET应用程序相比没有什么特别之处,这最终取决于用户的偏好。以下是Windows服务内部的ServiceStack应用程序的几个现有示例(即没有TopShelf):


自托管
AppSelfHostBase
通常是Windows服务将继承的,但是如果您不需要支持HTTP请求,您可以只继承
BasicAppHost
或公共
ServiceStackHost
(所有ServiceStack主机都继承该主机)。

我正在使用以下命令来启动app x.Service(s=>{s.ConstructUsing(name=>newapphost());s.WhenStarted(ah=>ah.Init());s.WhenStopped(ah=>ah.Dispose();});x.RunAsLocalSystem();
public class Program
{
    public static void Main()
    {
        HostFactory.Run(x =>                                 
        {
            x.Service<AppHost>(s =>                        
            {
                s.ConstructUsing(name => new AppHost());    
                s.WhenStarted(ah =>
                {
                    ah.Init();
                    ah.Start("http://*:8088/");
                    "Lead message processor listening at http://localhost:8088 ".Print();
                });              
                s.WhenStopped(ah => ah.Stop());              
            });
            x.RunAsLocalSystem();

            x.SetDescription("Processes all messages for the Leads application.");
            x.SetDisplayName("Leads Message Processor");
            x.SetServiceName("LOLeadsProcessor");                      
        });
    }
}

public class AppHost : AppSelfHostBase
{
    public AppHost()
        : base("LO.Leads.Processor", typeof(HelloService).Assembly)
    {
        // Logging
        LogManager.LogFactory = new NLogFactory();
    }

    public override void Configure(Container container)
    {

        //RabbitMQ
        container.Register<IMessageService>(c => new RabbitMqServer("cdev-9010.example.com", "test", "test")
        {
            AutoReconnect = true,
            DisablePriorityQueues = true,

        }); 
        RabbitMqServer mqServer = (RabbitMqServer)container.Resolve<IMessageService>();


        mqServer.RegisterHandler<HelloIntro>(m =>
        {
            return new HelloIntroResponse { Result = "Hello, {0}!".Fmt(m.GetBody().Name) };
        });

        mqServer.Start();

    }
}