【发布时间】:2012-06-02 23:27:13
【问题描述】:
我在我的项目中定义了一个覆盖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)
{
}
}
我是否遗漏了配置中的某些内容?
【问题讨论】:
标签: c# .net wcf exception-handling wcf-extensions