为什么我的自托管NancyFX应用程序在通过HTTPS运行时会挂起?

bio*_*tal 1 ssl self-hosting nancy

我写了一个Nancy 自托管应用程序.这旨在作为没有任何客户端界面的API运行.因此,它是通过TopShelf部署的控制台应用程序(请参阅下面的代码)

只要我运行标准的http,一切都运行得很好.但是,我需要通过https运行来保护此API (请参阅下面的SSL设置部分)

一旦我通过https运行服务,服务在第一次调用后挂起.要清楚,第一个调用工作正常,我收到正确的响应.因为第二次调用挂起并且仅在超时之后才返回,所以一定会出现问题.

这是Nancy自托管中的错误还是我在我的代码/设置中犯了错误?

谢谢.

控制台应用程序

public class Program
{
    [STAThread]
    public static void Main()
    {
        HostFactory.Run(config => {
            config.Service<SelfHost>(service =>
            {
                service.ConstructUsing(name => new SelfHost());
                service.WhenStarted(s=> s.Start());
                service.WhenStopped(s=> s.Stop());
            });
            config.RunAsLocalSystem();
            config.StartAutomatically();
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

自托管控制器

public class SelfHost
{
    private NancyHost nancyHost;

    public void Start()
    {
        var config = new HostConfiguration { 
            UnhandledExceptionCallback = e => Log.Error("Self Host Exception", e) 
        };
        nancyHost = new NancyHost(config, new Uri("https://myurl.com:8081"));
        nancyHost.Start();
    }

    public void Stop()
    {
        nancyHost.Stop();
    }
}
Run Code Online (Sandbox Code Playgroud)

南希模块

public class RootModule : NancyModule
{
    public RootModule()
    {
        Get["/"] = _ =>
        {
            return "Service is Running";
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

SSL设置

netsh http add sslcert ipport=0.0.0.0:8081 certhash=XXXX880f5e33288a4c88bb1d321d88d44d2XXXX appid={xxxxxxxx-e7e9-xxxx-94dd-5634a472f42d}
netsh http add urlacl url=https://myurl.com:8081/ user=MYDOMAIN\my-admin-user
Run Code Online (Sandbox Code Playgroud)

编辑1

根据@Steven Robbins的建议,我现在使用预发布的nuget包重新编译.不幸的是,最新的预发布包没有解决问题,但是我现在有一些非常有用的日志信息.

日志

//First Call - success
12:51:10|GET| /
12:51:10|OK | Service is Running    

//Second Call failure                                                                                                                                                                                                                        
12:51:12|Self Host Exception
12:51:12| Method    :AsyncProcessClientCertificate
12:51:12| Message   :Element not found

//Restart Service
12:51:41|Stopping Service
12:51:41|Self Host Exception
12:51:41| Method    :EndGetContext
12:51:41| Message   :The I/O operation has been aborted because of either a thread exit or an application request
12:51:41|Self Host Exception
12:51:41| Method    :EndGetContext
12:51:41| Message   :The I/O operation has been aborted because of either a thread exit or an application request

12:51:43|Starting on https://myurl.net:8081
Run Code Online (Sandbox Code Playgroud)

Ste*_*ins 5

如果你将配置对象传递给NancyHost构造函数,你可以挂钩未被捕获的错误 - 你可能会发现它因为客户端证书所做的更改而爆炸,这些更改将在0.18中修复,但如果你现在可以修复从CI Feed中抓取它:

http://www.myget.org/gallery/nancyfx