Question

I am working on a Silverlight 5 project and I am building an application that connects to a WCF service via SSL. This seemed to work in browser AND out of browser when I was connecting via HTTP. Now that I have implemented SSL, it only works in browser. Any ideas?

Was it helpful?

Solution

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. 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.

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. Out of Browser the build-in http stack is used which in turn uses the CA list of windows.

You can force Silverlight to use a certain http stack by adding these lines to the Application_Startup() in the App.xaml.cs:

 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. You can also do the reverse and use the build-in http stack, even when running inside the browser:

 WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);
 WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.ClientHttp);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top