加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – WCF错误:无法加载扩展名

发布时间:2020-12-15 18:30:42 所属栏目:百科 来源:网络整理
导读:我在我的项目中定义了一个类,它覆盖了IDispatchMessageInspector,我添加了相关的配置,但它不起作用 System.Configuration.ConfigurationErrorsException: The type ‘InMotionGIT_NT.Address.Service,CustomHeaders,Version=1.0.0.0,Culture=neutral,PublicK
我在我的项目中定义了一个类,它覆盖了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:UsersjmachadoDocumentsVisual Studio 2010ProjectsInMotionGIT_NTAddress ServiceInMotionGIT_NT.Address.ServicebinDebugInMotionGIT_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)
    {
    }
}

我是否会错过配置中的某些内容?

解决方法

更改您的类型定义.首先是完整类型名称(接口类名称).昏迷后,您将dll的名称保存为您的类型.而不是其余的.
像这样:
<behaviorExtensions>
    <add name="customHeaders" type="InMotionGIT_NT.Address.Service.CustomHeaders,<DLLName>,PublicKeyToken=null" />
</behaviorExtensions>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读