Asp.net web api 自托管NServiceBus中的主机Web Api

Asp.net web api 自托管NServiceBus中的主机Web Api,asp.net-web-api,nservicebus,Asp.net Web Api,Nservicebus,我正在寻找如何使用自托管的NServiceBus,它启动并托管Web Api。我似乎找不到这方面的任何资源。有人愿意给我指一个方向或提供一些例子吗 感谢这里是一个示例应用程序,它介绍了自托管NServiceBus时您应该知道的各种事情 主要代码如下 class SelfHostService : ServiceBase { IStartableBus bus; static void Main() { using (var service = new S

我正在寻找如何使用自托管的NServiceBus,它启动并托管Web Api。我似乎找不到这方面的任何资源。有人愿意给我指一个方向或提供一些例子吗


感谢

这里是一个示例应用程序,它介绍了自托管NServiceBus时您应该知道的各种事情

主要代码如下

class SelfHostService : ServiceBase
{
    IStartableBus bus;

    static void Main()
    {
        using (var service = new SelfHostService())
        {
            // so we can run interactive from Visual Studio or as a service
            if (Environment.UserInteractive)
            {
                service.OnStart(null);
                Console.WriteLine("\r\nPress any key to stop program\r\n");
                Console.Read();
                service.OnStop();
            }
            else
            {
                Run(service);
            }
        }
    }

    protected override void OnStart(string[] args)
    {
        LoggingConfig.ConfigureLogging();

        Configure.Serialization.Json();

        bus = Configure.With()
                       .DefaultBuilder()
                       .UnicastBus()
                       .CreateBus();
        bus.Start(() => Configure.Instance.ForInstallationOn<Windows>().Install());
    }

    protected override void OnStop()
    {
        if (bus != null)
        {
            bus.Shutdown();
        }
    }
}
class SelfHostService:ServiceBase
{
IStartableBus总线;
静态void Main()
{
使用(var service=new SelfHostService())
{
//因此,我们可以从VisualStudio或作为一项服务运行interactive
if(Environment.UserInteractive)
{
service.OnStart(null);
Console.WriteLine(“\r\n按任意键停止程序\r\n”);
Console.Read();
service.OnStop();
}
其他的
{
运行(服务);
}
}
}
启动时受保护的覆盖无效(字符串[]args)
{
LoggingConfig.ConfigureLogging();
Configure.Serialization.Json();
bus=Configure.With()
.DefaultBuilder()
.UnicastBus()
.CreateBus();
bus.Start(()=>Configure.Instance.ForInstallationOn().Install());
}
受保护的覆盖void OnStop()
{
如果(总线!=null)
{
总线关闭();
}
}
}

它还引导您通过各种sc.exe命令将其作为服务安装

查看MVC示例应用程序。设置应该是相同的。我认为@stephenl指的是NServiceBus托管WebApi还是WebApi托管NServiceBus?这通常是第二个问题,但这个问题似乎是倒退的。