[英]Setting custom WCF-binding behaviour via .config file - why doesn't this work?
我似乎遵循所有步骤,但我得到一个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>
这是异常消息:
为system.serviceModel / behavior创建配置节处理程序时发生错误:无法将扩展元素“myLoggerExtension”添加到此元素。 验证扩展是否已在system.serviceModel / extensions / behaviorExtensions的扩展集合中注册。 参数名称:element(C:\\ Documents and Settings \\ Andrew Shepherd \\ My Documents \\ Visual Studio 2008 \\ Projects \\ WcfPractice \\ ChatClient \\ bin \\ Debug \\ ChatClient.vshost.exe.config第5行)
我知道我已经正确地写了对ClientLoggingEndpointBehaviourExtensionobject的引用,因为通过调试器我可以看到它被实例化了。
这是一个随意的想法,但可能不是:反转配置中元素的顺序,因此扩展在行为之前 。
-Oisin
事实证明,我没有得到装配合格的名称。 程序集限定名称对于.NET框架的加载是正确的,但是在匹配行为配置时,WCF框架会执行一个简单的逐字符比较。
object, and wrote the AssemblyQualifiedName property to a local variable, which I then copy-and-pasted from the debug window into the .config file. 为了最终获得确切的类型名称,我编写了代码来创建对象的实例,并将AssemblyQualifiedName属性写入局部变量,然后将其从调试窗口复制并粘贴到.config文件中。
我不得不做所有这些被认为是WCF框架中的一个错误。 (见此链接 )显然它已在.NET 4.0中修复。
另见本文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.