自承载WCF使用的WebSockets使用SSL不工作 [英] Self hosted WCF using WebSockets is not working using SSL

查看:841
本文介绍了自承载WCF使用的WebSockets使用SSL不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制台应用程序这个code。
我想从开发工具镀铬连接,但得到这个错误,虽然这个问题是肯定的WCF端:

I have this code in console application. I am trying to connect from dev tools chrome, but get this error although the problem is for sure in WCF side:

WebSocket connection to 'wss://127.0.0.1:5650/Echo' failed: Error in connection establishment: net::ERR_CONNECTION_RESET

WSS 是不是打我的服务器code,没有例外,甚至没有日志。以最小的修改WS工作正常。我用的 Microsoft.WebSockets 的距离的NuGet简化code:

WSS is not hitting my server code, no exceptions not even logs. WS with minimum modifications is working fine. I used the Microsoft.WebSockets from nuget to simplify code:

WebSocketHost server = new WebSocketHost(typeof(EchoWSService), new Uri("https://127.0.0.1:5650/Echo"));
var bindingSsl = WebSocketHost.CreateWebSocketBinding(true);
server.AddWebSocketEndpoint(bindingSsl);
server.Open();

我已经尝试过自定义证书验证,但我说这是不是打我的code。

I already tried a Custom Cert Validator, but as I said it is not hitting my code.

现在我有同样的code除外的 server.Open()的一个ASP.net应用程序中使用的 ServiceRoute 的,并且它正在pretty精细!是使用SSL和VS的IIS前preSS生成的自签名的证书:

Now I have the same code except the server.Open() in a ASP.net app using ServiceRoute, and it is working pretty fine! yes with SSL and a self signed cert generated by VS for IIS express:

RouteTable.Routes.Add(new ServiceRoute("Echo", new TRWebSocketServiceFactory(), typeof(EchoWSService)));

在浏览器端仅是:

The browser side only is:

var ws = new WebSocket('wss://127.0.0.1:5650/Echo')

的web.config 的我根本就没有

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

那么,为什么地狱不工作我的自我承载的WCF在一个简单的控制台应用程序?

So why the hell is not working my self hosted WCF in a simple console app?

推荐答案

好吧,我终于得到这个自签名的证书,并通过COMODO颁发的证书工作。
我调查什么IIS不和模仿,它结合在操作系统级别的端口和主机。我根据这个结果在这个 $ C $的CProject帖子

All right, finally I got this working with self signed cert and also with a cert issued by COMODO. I investigated what IIS does and mimic that, it binds the port and host at OS level. I based this result in this codeproject post.

1。安装在主机机的证书。
为了测试的建议我使用它与V​​S的IIS生成的自签名证书。您可以使用另一个或makecert.exe自己做的。在个人→证书安装即可。
 

2。固定插座通过命令行的管理运行:

netsh http add sslcert ipport=0.0.0.0:5650 certhash=xxxxxxx.. appid={xxxx-xxx..} certstorename=MY
netsh http add sslcert hostnameport=domainnamne:5650 certhash=xxxxxxx.. appid={xxxx-xxx..} certstorename=MY

其中:


  • ipport和hostnameport = 是IP,主机或域名和端口绑定到该证书。

  • CERTHASH = 是证书的拇指打印不带空格。

  • 的appid = 什么是GUID,它应该确定哪些应用程序正在使用它。

  • certstorename = 到证书的路径,在这种情况下,我个人的手段证书→

  • ipport and hostnameport = Are the ip, host or domain and port bind to the certificate.
  • certhash = Is the cert’s thumb print without spaces.
  • appid = Is whatever GUID, it is supposed to identify what app is using it.
  • certstorename = The path to the cert, in this case MY means Personal→Certificates

在Windows Server 2008中,我们可以使用* httpcfg.exe ***为同一提案。
一旦绑定成功,我们可以通过运行回顾:

In Windows Server 2008, we can use *httpcfg.exe*** for same proposal. Once it binds successful we can review by running:

netsh http show sslcert

我们将获得:

Hostname:port                : domainname:5650
Certificate Hash             : xxxxxxx..
Application ID               : {xxxx-xxx..}
Certificate Store Name       : MY
Verify Client Certificate Revocation : Enabled
…

3。接受浏览器端的证书。 则不需要此步的,如果我们有一个有效可信的证书。

3. Accept the cert in browser side. This step is not needed if we have a valid trusted certificate.

因此​​,为了使浏览器接受证书,导航到的https://域名:5650 (域名必须匹配一个你习惯在步骤2中绑定)
然后我们在对话框接受证书,铬也许需要导航到的https://域名:5650 /服务

So to make the browser accept the cert, navigate to https://domainname:5650 (domain name must match the one you used to bind in step 2) Then we get the dialog to accept the cert, in chrome maybe needed to navigate to https://domainname:5650/Service.

在这里输入的形象描述

和瞧,在控制台中,您可以试试:

And Voila, in console you can try:

ws = new WebSocket('wss://domainname:5650/Service');

和没有例外。

在这里输入的形象描述

这篇关于自承载WCF使用的WebSockets使用SSL不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆