2012-10-10 90 views
0

我有在代碼中的WebAPI服務,在應用程序啓動運行此配置:WCF的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> 

回答

0

這是正確的。

但是您正在使用WCF Web API,實際上ASP.NET Web API的CTP版本,所以我建議您遷移到它。這並不難,因爲它們是相似的。

另一個需要遷移的原因是,當我使用WCF Web API時,使用配置來配置HTTPS和安全性,並不適合我。配置編程工作。所以我認爲這是一種錯誤。

+0

你是怎麼知道它是CTP而不是最終版本的?是因爲我提到它還是代碼中有不同的東西?另外,我不需要在代碼和錯誤處理程序中添加一些等同於CreateInstance位的配置嗎? – kabaros

+0

只是添加到我的評論,對System.ServiceModel的任何引用意味着它使用WCF ..並且我們不需要添加CreateInstance位(錯誤處理程序可以以與MVC應用程序相同的方式完成) – kabaros