2012-05-28 41 views
6

我在我的項目,該項目將覆蓋IDispatchMessageInspector定義一個類,我添加相關的配置,但它不工作WCF錯誤:擴展無法加載

System.Configuration.ConfigurationErrorsException: The type 'InMotionGIT_NT.Address.Service, CustomHeaders, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' registered for extension 'customHeaders' could not be loaded. (C:\Users\jmachado\Documents\Visual Studio 2010\Projects\InMotionGIT_NT\Address Service\InMotionGIT_NT.Address.Service\bin\Debug\InMotionGIT_NT.Address.Service.dll.config line 67)

這是我打電話給我的定義擴展

<endpointBehaviors> 
    <behavior name="jsonBehavior"> 
     <enableWebScript/> 
     <customHeaders/> 
     <!--<webHttp/>--> 
    </behavior> 
</endpointBehaviors>  

這是我如何定義我的自定義擴展

<behaviorExtensions> 
    <add name="customHeaders" type="InMotionGIT_NT.Address.Service, CustomHeaders, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
</behaviorExtensions> 

這裏的我定義的類,這是我的項目

[AttributeUsage(AttributeTargets.Class)] 
public class CustomHeaders : IDispatchMessageInspector 
{ 
    public object AfterReceiveRequest(ref Message request, ClientChannel channel, InstanceContext instanceContext) 
    { 
     if ((WebOperationContext.Current.IncomingRequest.Method == "GET")) 
     { 
      WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); 
      WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "POST"); 
      WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept"); 
     } 
     return null; 
    } 

    public void BeforeSendReply(ref Message reply, object correlationState) 
    { 
    } 
} 

我錯過配置中的東西嗎?

回答

17

更改您的類型定義。首先是完整的類型名稱(接口+類名稱)。昏迷後,你把你的類型的DLL名稱。和其餘的一樣。 像這樣:

<behaviorExtensions> 
    <add name="customHeaders" type="InMotionGIT_NT.Address.Service.CustomHeaders, <DLLName> , Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
</behaviorExtensions> 
0

確保版本與dll版本相同。在我的情況下,我引用了這些類是其中一部分的相同asssemlby。但是我改變了AssemlbyInfo.cs文件中與App.config文件中的版本不匹配的程序集版本。