Silverlight and SSL WCF Web service


How to get your Silveright application to workwith a WCF web service using SSL / https? You'll need to change a few things. I'll explain them here.

First, make sure your service is accessible under https. You can do that by adding a binding configuration.

        <binding name="HttpsBinding">
          <security mode="Transport" />

Add this binding configuration in the "system.serviceModel" section.

Now tell your web service endpoint to make use of this binding:
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="HttpsBinding" etc...

Client (Silverlight)
That was the server side of the web service, you will also need to change the client side (Silveright). In Silverlight, there a ServiceReferences.ClientConfig file, it defines the binding of the WCF web service.

Change this line:
<security mode="None" />

in: <security mode="Transport" />

Also make sure the endpoint points to the correct https:// address in this configuration file.

Finally, check the way you are instantiating your proxy in Silverlight code.

It must be like this:
WcfServiceClient proxy = new WcfServiceClient();

You can not make your proxy like this for SSL web services:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("https://etc");
WcfServiceClient proxy  = new WcfServiceClient(binding, address);

If you're making the proxy like the last example, you're overriding the values in your ServiceReferences.ClientConfig file. The binding also has to know it must use Transport mode security.

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);


Dennis 14-07-2009
Thanks for this. Worked like a charm. Now I'm trying to get SSL working with Silverlight 3's ability to use binaryXML services. Any tips? :)

Dennis 18-07-2009
I guess it was just as simple as changing <httpTransport to <httpsTransport in the ServiceReferences.ClientConfig as well as in the web.config for the default binaryXML setup.

rob 02-08-2009
Are there any other steps i need to do, like installing certificate from somewhere or something? The problem i'm getting in VS is general exception and inner exception tells something about certificate installation, etc.

Steve 11-06-2012
Hi, I'm using an ASP.NET .ashx HTTP Handler with the single file uploader and using the javascript events. This works perfect without SSL and mostly with SSL but your fileUploader.Content.Files.ErrorOccurred event does not fire when in SSL? (This normally occures when I raise an exception in the HTTP handler). Should this work under SSL? Where is this ServiceReferences.ClientConfig file, is it not required with the silverlight source to be compiled with the XAP? And you haven't supplied the silver light source code! Any help appreciated.

New Comment

E-mail (not published)
Enter the code shown: