This project is read-only.

HTTPS configuration for Web API on IIS 7.5

Topics: Web Api
Jun 3, 2011 at 2:33 PM

I'm really close to getting this to work.  I've got IIS setup for HTTPS binding with a properly installed certificate.  I'm currently getting this error:

Type 'Microsoft.ApplicationServer.Http.HttpResponseMessage`1[System.String]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

My resource class is this:


namespace BodyTalkAPI.Resources
  public class MainResource
    [WebGet(UriTemplate = "{dataValue}")]
    HttpResponseMessage<string> GetData(int dataValue)
      HttpResponseMessage<string> hrm = new HttpResponseMessage<string>(string.Format("you entered {0}", dataValue));
      return hrm;



My web.config is this:

        <binding name="BodyTalkSecureBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" />
        <behavior name="BodyTalkBehavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
      <service name="BodyTalkAPI.Resources.MainResource" behaviorConfiguration="BodyTalkBehavior">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="BodyTalkSecureBinding" contract="BodyTalkAPI.Resources.MainResource" />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

Jun 20, 2011 at 12:00 AM

That won't work as you are using the webHttpBinding. Web API uses a new binding called HttpBinding. You can't set it via config in the same way as it requires changes in our 4.0 bits. It is possible, but it's much more verbose as you have to specify the binding namespace / assembly explicitly.

The easiest way to do this now is via a custom service host. If you look at this post: you will see an HttpsServiceHostFactory that you can use.