通过 .config 文件设置自定义 WCF 绑定行为 - 为什么这不起作用?

发布于 2024-09-03 17:03:29 字数 2039 浏览 9 评论 0 原文

我正在尝试按照示例 此处。

我似乎遵循了所有步骤,但我得到了 ConfigurationErrorsException。有没有比我更有经验的人可以发现我做错了什么?

这是整个 app.config 文件。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="ClientLoggingEndpointBehaviour">
                    <myLoggerExtension />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <extensions>
            <behaviorExtensions>
                <add name="myLoggerExtension"
                     type="ChatClient.ClientLoggingEndpointBehaviourExtension, ChatClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"/>
            </behaviorExtensions>
        </extensions>
        <bindings>
        </bindings>
        <client>
            <endpoint
                behaviorConfiguration="ClientLoggingEndpointBehaviour"
                name="ChatRoomClientEndpoint"
                address="http://localhost:8016/ChatRoom"
                binding="wsDualHttpBinding"
                contract="ChatRoomLib.IChatRoom"
                />
        </client>
    </system.serviceModel>
</configuration>

这是异常消息:

创建时发生错误 配置节处理程序 系统.服务模型/行为: 扩展元素“myLoggerExtension” 无法添加到此元素。 验证扩展名是否为 在扩展集合中注册 在 系统.serviceModel/扩展/行为扩展。 参数名称:元素(C:\Documents 和设置\安德鲁·谢泼德\我的 文档\Visual Studio 2008\项目\WcfPractice\ChatClient\bin\调试\ChatClient.vshost.exe.config 第 5 行)

我知道我已经正确编写了对 ClientLoggingEndpointBehaviourExtension 对象的引用,因为通过调试器我可以看到它被实例化。

I am attempting to insert a custom behavior into my service client, following the example here.

I appear to be following all of the steps, but I am getting a ConfigurationErrorsException. Is there anyone more experienced than me who can spot what I'm doing wrong?

Here is the entire app.config file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="ClientLoggingEndpointBehaviour">
                    <myLoggerExtension />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <extensions>
            <behaviorExtensions>
                <add name="myLoggerExtension"
                     type="ChatClient.ClientLoggingEndpointBehaviourExtension, ChatClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"/>
            </behaviorExtensions>
        </extensions>
        <bindings>
        </bindings>
        <client>
            <endpoint
                behaviorConfiguration="ClientLoggingEndpointBehaviour"
                name="ChatRoomClientEndpoint"
                address="http://localhost:8016/ChatRoom"
                binding="wsDualHttpBinding"
                contract="ChatRoomLib.IChatRoom"
                />
        </client>
    </system.serviceModel>
</configuration>

Here is the exception message:

An error occurred creating the
configuration section handler for
system.serviceModel/behaviors:
Extension element 'myLoggerExtension'
cannot be added to this element.
Verify that the extension is
registered in the extension collection
at
system.serviceModel/extensions/behaviorExtensions.
Parameter name: element (C:\Documents
and Settings\Andrew Shepherd\My
Documents\Visual Studio
2008\Projects\WcfPractice\ChatClient\bin\Debug\ChatClient.vshost.exe.config
line 5)

I know that I've correctly written the reference to the ClientLoggingEndpointBehaviourExtensionobject, because through the debugger I can see it being instantiated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清晨说晚安 2024-09-10 17:03:29

这是一个有点随机的想法,但也许不是:颠倒配置中元素的顺序,以便扩展出现在行为之前。

-奥辛

This is a bit of a random thought, but maybe not: reverse the order of the elements in your config so extensions come before behaviors.

-Oisin

寒尘 2024-09-10 17:03:29

事实证明,我没有完全正确地获得程序集限定名称。
程序集限定名称足够正确,可供 .NET 框架加载,但随后 WCF 框架在匹配行为配置时会执行简单的逐字符比较。

为了最终获得准确的类型名称,我编写了代码来创建 ClientLoggingEndpointBehaviourExtension 对象的实例,并编写了 AssemblyQualifiedName 属性到本地变量,然后我将其从调试窗口复制并粘贴到 .config 文件中。

我必须做的这一切被认为是 WCF 框架中的一个错误。
(请参阅此链接
显然它已在 .NET 4.0 中修复。

另请参阅 这篇文章。

It turns out that I didn't get the assembly qualified name EXACTLY right.
The assembly qualified name was correct enough for the .NET framework to load, but then the WCF framework performs a naive character-by-character comparison when matching the behavior configurations.

To finally get the exact type name, I wrote code to create an instance of ClientLoggingEndpointBehaviourExtension object, and wrote the AssemblyQualifiedName property to a local variable, which I then copy-and-pasted from the debug window into the .config file.

That I had to do all this is considered to be a bug in the WCF framework.
(See this link)
Apparently it's fixed in .NET 4.0.

Also see this article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文