Windows Phone 7 - 3 Steps to configure WCF Rest with SSL

26 September 2010

If you are developing an app which requires a secure SSL web service connection that is under your control, you may have opted for WCF.

This post assumes you have accepted JSON over XML and REST over SOAP. It also assumes you know how to configure an SSL certificate in IIS. Lastly, it assumes you are using WCF 4.0 as part of .net 4.0 on IIS7.x.

Phew, with that out of the way, here are 3 quick steps to enabling SSL WCF Rest services.

FIrstly,  add the factory attribute on your .svc service.

<%@ ServiceHost Language="C#" Debug="true" Service="WebServices.YourService"
Factory="System.ServiceModel.Activation.WebServiceHostFactory" CodeBehind="YourService.svc.cs" %>

Secondly,  put the asp.net compatibility attribute on your .svc.cs implementation class.

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class YourService : IYourService

And finally, add your configuration and leave to simmer for 60 seconds before bringing to the boil. If you have no need for port 80, just remove the binding in IIS entirely and have 443 only.

Note that www.godaddy.com certs work dandy with WP7 and they are pretty cheap as well, you don’t need a big fancy $300 Verisign one.

<bindings>
    <webHttpBinding>
        <binding>
            <security mode="Transport" />
        </binding>
    </webHttpBinding>
</bindings>
<standardEndpoints>
    <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="false" automaticFormatSelectionEnabled="true" />
    </webHttpEndpoint>
</standardEndpoints>
Want to get started?

We would love to help with your next app or game, please do get in touch.