我在我的项目中定义了一个覆盖IDispatchMessageInspector
并添加了相关配置的类,但它不起作用
System.Configuration.ConfigurationErrorsException:无法加载为扩展“customHeaders”注册的类型“InMotionGIT_NT.Address.Service、CustomHeaders、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null”。(C:\Users\jmachado\Documents\Visual Studio 2010\Projects\InMotionGIT_NT\Address Service\InMotionGIT_NT.Address.Service\bin\Debug\InMotionGIT_NT.Address.Service.dll.config 第 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)
{
}
}
我错过了配置中的某些内容吗?