Wcf WebApi 配置等效于代码



我在应用程序启动时运行的代码中对WebApi服务进行了以下配置:

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())
};

现在,我想把它从代码中移出来,并在web.config中完成。 等价物是什么?到目前为止,我在web.config的运行时下有这个,我不确定它是否正确,而且我不知道CreateInstance和ErrorHandlers会在配置中转换为什么:

<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>

>这是正确的。

但是您使用的是WCF Web API,实际上是 ASP.NET Web API的CTP版本,因此我建议您迁移到它。这并不难做到,因为它们很相似。

迁移的另一个原因是,当我使用 WCF Web API 时,使用 config 配置 HTTPS 和安全性对我来说不起作用。以编程方式进行配置。所以我认为这是某种错误。

最新更新