Dealing with Silverlight and SSL and without SSL
Silverlight can without any problem talk to HTTP or HTTPS.
So if you do not know where will be deployed you’ll need to make sure your application will work well in both scenarios.
All your web services will need two configuration on the binding of the protocol.
<configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_SilverlightWebService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <security mode="None" /> </binding> <binding name="BasicHttpBinding_SilverlightWebServiceSSL" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <security mode="Transport" /> </binding> </basicHttpBinding> </bindings>
One for not security (None) and the other for SSL (Transport)
Second, you’ll have to create a class inheriting from the base proxy class of the service.
public class SilverlightWebServiceProxy : SLService.SilverlightWebServiceClient
Then detect if is in https and use the correct security model.
base.Endpoint.Contract.Name = base.Endpoint.Contract.Name + "SSL";
This is simple, yet you need to make sure all the resources that you accessed in HTTP are accessible in HTTPS.
Please make sure to use the correct clientaccesspolicy.xml that explicitly says that https is ok to access the resources, otherwise Silverlight will failed.
<?xml version="1.0" encoding="utf-8" ?> <access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="SOAPAction"> <domain uri="http://*" /> <domain uri="https://*" /> </allow-from> <grant-to> <resource include-subpaths="true" path="/"/> </grant-to> </policy> </cross-domain-access> </access-policy>
Hope this helps
Cheers
Al



Comments
Morten said on 6.05.2009 at 9:46 PM
"Please make sure to use the correct clientaccesspolicy.xml that explicitly says that https is ok to access the resources, otherwise Silverlight will fail"
Actually it's the other way around. You have to explicitly allow for HTTP, or else you can only access your SSL hosted service from a SSL hosted control. "*" basically means "whatever i'm hosted on and safer". So on HTTP, connections from HTTPS is ok because they are more secure, but when hosting on HTTPS, connections from HTTP are less secure, and is denied by default. That's why you have to explicitly opt your service in to getting requests from "unsecure" clients.