我在我的项目中定义了一个类,它覆盖了IDispatchMessageInspector,我添加了相关的配置,但它不起作用
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,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) { } }
我是否会错过配置中的某些内容?