简体   繁体   English

Silverlight 5通过SSL连接到WCF服务

[英]Silverlight 5 connecting to WCF service via ssl

I am working on a Silverlight 5 project and I am building an application that connects to a WCF service via SSL. 我正在开发Silverlight 5项目,正在构建通过SSL连接到WCF服务的应用程序。 This seemed to work in browser AND out of browser when I was connecting via HTTP. 当我通过HTTP连接时,这似乎在浏览器中以及在浏览器外均有效。 Now that I have implemented SSL, it only works in browser. 现在,我已经实现了SSL,它仅在浏览器中有效。 Any ideas? 有任何想法吗?

Without any additional details it's hard to guess what is going wrong, but my best guess would be that the certificate you use isn't trusted by Windows, while it is trusted by your browser. 没有任何其他详细信息,很难猜测出了什么问题,但是我最好的猜测是,所使用的证书不受Windows信任,而受浏览器信任。 Are you using some self-signed certificate which you imported into the browser? 您是否正在使用导入到浏览器中的一些自签名证书? If you are you should import into the windows certificate store as well. 如果您是您,则也应该导入Windows证书存储区。

When running inside the browser Silverlight will do all http(s) calls through the browser, so it will be the browser which decides whether or not the certificate is trusted. 在浏览器中运行时,Silverlight将通过浏览器进行所有http(s)调用,因此由浏览器决定证书是否受信任。 Out of Browser the build-in http stack is used which in turn uses the CA list of windows. 在浏览器外,使用内置的HTTP堆栈,该堆栈又使用Windows的CA列表。

You can force Silverlight to use a certain http stack by adding these lines to the Application_Startup() in the App.xaml.cs: 通过将以下行添加到App.xaml.cs中的Application_Startup()中,可以强制Silverlight使用某个http堆栈:

 WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.BrowserHttp);
 WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.BrowserHttp);

This will make your your application use the IE stack when running Out of Browser. 这将使您的应用程序在“浏览器”中运行时使用IE堆栈。 You can also do the reverse and use the build-in http stack, even when running inside the browser: 即使在浏览器中运行,您也可以执行相反的操作并使用内置的http堆栈:

 WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);
 WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.ClientHttp);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM