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.
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.