Question

I have this configuration for a WebApi service in code that runs on Application start:

var configuration = new WebApiConfiguration
{
    Security = (uri, binding) => {
        binding.Mode = HttpBindingSecurityMode.TransportCredentialOnly; 
        binding.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
    },
    CreateInstance = ((type, requestMessage, o) => container.Resolve(type)),
    ErrorHandlers = (handlers, endpoint, description) => handlers.Add(new GlobalErrorHandler())
};

Now, I want to move this out of code and do it in web.config. what will the equivalent be? I have this so far under runtime in web.config, I am not sure if it's correct and also I don't know what CreateInstance and ErrorHandlers would translate to in configuration:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttp">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows"></transport>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>
  </system.serviceModel>
Was it helpful?

Solution

It's correct.

But you are using WCF Web API, what is actually CTP version of ASP.NET Web API, so I suggest you to migrate to it. It's not hard to do, because they are similar.

And one more reason to migrate is, when I was using WCF Web API, configuring HTTPS and security using config, didn't worked by me. Configuring programmatically worked. So I think it was some kind of bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top