<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Development</title>
        <link>http://jamescbender.com/bendersblog/category/6.aspx</link>
        <description>Development</description>
        <language>en-US</language>
        <copyright>James Bender</copyright>
        <managingEditor>james.c.bender@live.com</managingEditor>
        <generator>Subtext Version 1.9.5.177</generator>
        <item>
            <title>Extending WCF using the IInstanceProvider and IServiceBehavior Interfaces</title>
            <link>http://jamescbender.com/bendersblog/archive/2008/04/09/extending-wcf-using-the-iinstanceprovider-and-iservicebehavior-interfaces.aspx</link>
            <description>&lt;p&gt;Recently, meaning yesterday, two of my colleagues, &lt;a target="_blank" href="http://krisscott.net/Default.aspx"&gt;Kriss Scott&lt;/a&gt; and &lt;a target="_blank" href="http://programwith.net/"&gt;Matt Casto&lt;/a&gt; ran into an issue with one of WCF services.&lt;/p&gt;
&lt;p&gt;To make a long story short, they needed to do some policy injection, which one or both of them will probably blog about at some point. The difficulty was getting access to the constructor of the WCF service object.&lt;/p&gt;
&lt;p&gt;Luckily the ability to create custom behaviors in WCF makes this relatively easy.&lt;/p&gt;
&lt;p&gt;The first step was to choose what type of functionality the behavior needed to provide. Since we are looking to effect the way the service object is created, IInstanceProvider was the obvious choice. Kriss and Matt also wanted this behavior to effect all calls to this service object, so IServiceBehavior was also to be used.&lt;/p&gt;
&lt;h2&gt;What's different?&lt;/h2&gt;
&lt;p&gt;In my last series of posts on behaviors, I created a behavior based on the IDispatchMessageInspector which, hence the name, attached to (and effected) the behavior of the message dispatcher in the WCF runtime. If you remember from my previous posts, the Dispatchers are responsible for passing messages around the runtime and controlling service runtime attributes (channel dispatcher is connected to the endpoint dispatcher, the endpoint dispatcher is connected to the operation dispatcher, the operation dispatcher is connected to the operation). This was implemented as an IEndpointBehavior which meant that it was applied to a specific endpoint. So, if a message came through the endpoint we applied the behavior to, the behavior logic would execute. If a message come into the same operation of the same service but through a different endpoint the behavior would not execute.&lt;/p&gt;
&lt;p&gt;We "attached" our behavior (in code) thusly...&lt;/p&gt;
&lt;p&gt;In the hosting code, before we opened the host, we added an instance of the behavior to the behavior collection for our endpoint:&lt;/p&gt;
&lt;pre class="code"&gt;host.Description.Endpoints[0].Behaviors.Add(&lt;span style="COLOR: blue"&gt;new &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;MyCustomMessageFormatter&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"message"&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;This caused the runtime to call the ApplyDispatchBehavior of our custom behavior object:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;public void &lt;/span&gt;ApplyDispatchBehavior(&lt;span style="COLOR: #2b91af"&gt;ServiceEndpoint &lt;/span&gt;endpoint, &lt;span style="COLOR: #2b91af"&gt;EndpointDispatcher &lt;/span&gt;endpointDispatcher)
{
    endpointDispatcher.DispatchRuntime.MessageInspectors.Add(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;);
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;This was the code actually responsible for adding our custom logic to the correct place in the WCF runtime, in this case the MessageInspectors collection for the EndpointDispatcher passed in from the WCF runtime. If this code wasn't here, the behavior would never have actually been implemented in our service.&lt;/p&gt;
&lt;p&gt;But that was IDispatchMessageInspector and IEndpointBehavior.&lt;/p&gt;
&lt;h2&gt;IInstanceProvider and IServiceBehavior are different animals.&lt;/h2&gt;
&lt;p&gt;For starters, your implementation of IInstanceProvider has to be attached to the endpoint dispatchers instance provider. Unlike the message inspector, there can only be one instance provider per endpoint. &lt;/p&gt;
&lt;p&gt;But there are a couple little "wrinkles" in this whole thing. Remember when I said that Matt and Kriss wanted to implement this at the service level and not the endpoint level? That means they need to use IServiceBehavior, not IEndpointBehavior. Well, like IEndpointBehavior, IServiceBehavior has an implementation of the ApplyDispatchBehavior:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;public void &lt;/span&gt;ApplyDispatchBehavior(&lt;span style="COLOR: #2b91af"&gt;ServiceDescription &lt;/span&gt;serviceDescription, 
    &lt;span style="COLOR: #2b91af"&gt;ServiceHostBase &lt;/span&gt;serviceHostBase)
{

}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;One thing you may notice is that unlike the endpoint behaviors version of ApplyDispatchBehavior, we get references to ServiceDescription and ServiceHostBase passed in; not ServiceEndpoint or EndpointDispatcher. But, we need to attach this behavior to an endpoint. Here's how we do it:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;public void &lt;/span&gt;ApplyDispatchBehavior(&lt;span style="COLOR: #2b91af"&gt;ServiceDescription &lt;/span&gt;serviceDescription, 
    &lt;span style="COLOR: #2b91af"&gt;ServiceHostBase &lt;/span&gt;serviceHostBase)
{
    &lt;span style="COLOR: blue"&gt;foreach &lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;ChannelDispatcherBase &lt;/span&gt;channelDispatcherBase &lt;span style="COLOR: blue"&gt;in &lt;/span&gt;serviceHostBase.ChannelDispatchers)
    {
        &lt;span style="COLOR: #2b91af"&gt;ChannelDispatcher &lt;/span&gt;channelDispatcher = channelDispatcherBase &lt;span style="COLOR: blue"&gt;as &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;ChannelDispatcher&lt;/span&gt;;
        &lt;span style="COLOR: blue"&gt;if &lt;/span&gt;(channelDispatcher != &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)
        {
            &lt;span style="COLOR: blue"&gt;foreach &lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;EndpointDispatcher &lt;/span&gt;endpoint &lt;span style="COLOR: blue"&gt;in &lt;/span&gt;channelDispatcher.Endpoints)
            {
                endpoint.DispatchRuntime.InstanceProvider = &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;;
            }
        }
    }
}&lt;/pre&gt;
&lt;p&gt;Service host base gives us access to the collection of channel dispatchers, which in turn gives us a collection of endpoint dispatchers. From here it's a simple matter to iterate through each collection and attach the behavior as need.&lt;/p&gt;
&lt;p&gt;This is the easy example. I'm just attaching the behavior to all the endpoints in all the channel dispatchers for this service. If I wanted to I could examine each endpoint and make some kind of determination about what kind of action I wanted to take on that endpoint. In this case we didn't need to.&lt;/p&gt;
&lt;p&gt;From here it's a simple matter to add it to our runtime from code (remember to do this BEFORE you call host.Open()):&lt;/p&gt;
&lt;pre class="code"&gt;host.Description.Behaviors.Add(&lt;span style="COLOR: blue"&gt;new &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;MyInstanceProvider&lt;/span&gt;());&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Or from configuration:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;service &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;Sample.HelloWCF&lt;/span&gt;" &lt;span style="COLOR: red"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MyInstanceProviderBehavior&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviors&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;serviceBehaviors&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behavior &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MyInstanceProviderBehavior&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;MyInstanceProvider&lt;/span&gt;&lt;span style="COLOR: blue"&gt;/&amp;gt;
&lt;/span&gt;&lt;span style="COLOR: blue"&gt;        &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behavior&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;serviceBehaviors&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviors&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;extensions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MyInstanceProvider&lt;/span&gt;"
             &lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;CustomBehaviorSample.InstanceProviderExtensionElement, Behavior, &lt;/span&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;
&lt;/span&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviorExtensions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;extensions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Remember, to add this behavior via configuration, you'll need a class based on BehaviorExtensionElement to do the "heavy lifting." I covered this &lt;a target="_blank" href="http://jamescbender.com/bendersblog/archive/2008/03/01/making-wcf-quotbehavequot---part-three.aspx"&gt;here&lt;/a&gt; and a bit more &lt;a target="_blank" href="http://jamescbender.com/bendersblog/archive/2008/04/02/making-wcf-quotbehavequot---part-four.aspx"&gt;here&lt;/a&gt;. This time around our implementation is much simpler since we aren't passing any information in at configuration and we are starting with our behavior extension element as a separate class:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;class &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;InstanceProviderExtensionElement &lt;/span&gt;: &lt;span style="COLOR: #2b91af"&gt;BehaviorExtensionElement
&lt;/span&gt;{
    &lt;span style="COLOR: blue"&gt;protected override object &lt;/span&gt;CreateBehavior()
    {
        &lt;span style="COLOR: blue"&gt;return new &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;MyInstanceProvider&lt;/span&gt;();
    }

    &lt;span style="COLOR: blue"&gt;public override &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;Type &lt;/span&gt;BehaviorType
    {
        &lt;span style="COLOR: blue"&gt;get &lt;/span&gt;{ &lt;span style="COLOR: blue"&gt;return typeof &lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;MyInstanceProvider&lt;/span&gt;); }
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;The last step is to implement the methods from IInstanceProvider:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;public object &lt;/span&gt;GetInstance(&lt;span style="COLOR: #2b91af"&gt;InstanceContext &lt;/span&gt;instanceContext)
 {
     &lt;span style="COLOR: blue"&gt;return &lt;/span&gt;GetInstance(instanceContext, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;);
 }

 &lt;span style="COLOR: blue"&gt;public object &lt;/span&gt;GetInstance(&lt;span style="COLOR: #2b91af"&gt;InstanceContext &lt;/span&gt;instanceContext, &lt;span style="COLOR: #2b91af"&gt;Message &lt;/span&gt;message)
 {
     &lt;span style="COLOR: blue"&gt;return new &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;HelloWCF&lt;/span&gt;();
 }

 &lt;span style="COLOR: blue"&gt;public void &lt;/span&gt;ReleaseInstance(&lt;span style="COLOR: #2b91af"&gt;InstanceContext &lt;/span&gt;instanceContext, &lt;span style="COLOR: blue"&gt;object &lt;/span&gt;instance)
 {
     &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
 }&lt;/pre&gt;
&lt;p&gt;As you see, this is relatively trivial. We have two overrides of the GetInstance method; one that takes a message (in case we want to inspect the message before deciding what kind of object to return) and one that doesn't. We also have a ReleaseInstance method to allow us to perform any additional cleanup that is needed.&lt;/p&gt;
&lt;p&gt;So, that's all there is too it! If you have any questions feel free to leave a comment or ping me on twitter.&lt;/p&gt;
&lt;p&gt;Later!&lt;/p&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/14.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2008/04/09/extending-wcf-using-the-iinstanceprovider-and-iservicebehavior-interfaces.aspx</guid>
            <pubDate>Wed, 09 Apr 2008 15:15:39 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/14.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2008/04/09/extending-wcf-using-the-iinstanceprovider-and-iservicebehavior-interfaces.aspx#feedback</comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/14.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Making WCF &amp;quot;Behave&amp;quot; - Part Three</title>
            <link>http://jamescbender.com/bendersblog/archive/2008/03/01/making-wcf-quotbehavequot---part-three.aspx</link>
            <description>&lt;p&gt;When last we left our weary adventures, they had created a custom WCF Behavior based on the IDispatchMessageInspector that when attached to an endpoint of a WCF service intercepted the outgoing message and replaced it with it's own nefarious text (&lt;a href="http://benders-blog.blogspot.com/2008/02/making-wcf-part-two.html"&gt;see here&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Their plan was brilliant! Brilliant that is, except for one minor detail.&lt;/p&gt;
&lt;p&gt;You see, in their haste our motley crew had simply attached the behavior to the endpoint at runtime when the service host was initiated. They quickly realized that the real power of WCF is the ability to change behaviors via configuration. This would require a little more work...&lt;/p&gt;
&lt;p&gt;Now, back to our story...&lt;/p&gt;
&lt;p&gt;In order to be able to add our custom behavior through configuration, we need to make sure the WCF Service Model knows it exists. We do this by having our behavior inherit from System.ServiceModel.Configuration.BeahviorExtensionElement. This gives us an abstract property called "BehaviorType" which tells the service model the type of our custom Behavior, and an abstract method "CreateBehavior" which actually returns an instance of our custom behavior. &lt;/p&gt;
&lt;p&gt;For this example I've chosen to implement this in my actual custom behavior class. And yes, if that was the way you do it all the time the service model should be smart enough to get the type and call a default constructor on our custom behavior. But the reason for this base class, and the methods it exposes, is that you could implement all of this in a class other than your actual behavior. This allows a lot of power in the way that custom behaviors are created, and I will cover strategies for this in another post.&lt;/p&gt;
&lt;p&gt;Anyway...&lt;/p&gt;
&lt;p&gt;If we add this to the custom behavior from last time, we get:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;class &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;MyCustomMessageFormatter &lt;/span&gt;: &lt;span style="COLOR: #2b91af"&gt;BehaviorExtensionElement&lt;/span&gt;,
    &lt;span style="COLOR: #2b91af"&gt;IDispatchMessageInspector&lt;/span&gt;, 
    &lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: #2b91af"&gt;IEndpointBehavior
&lt;/span&gt;{
    &lt;span style="COLOR: blue"&gt;...&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;&lt;/span&gt;&lt;font size="4"&gt;    &lt;span style="COLOR: blue"&gt;public override &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;Type &lt;/span&gt;BehaviorType
    {
        &lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;get 
        &lt;/span&gt;{ 
            &lt;span style="COLOR: blue"&gt;return typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;MyCustomMessageFormatter&lt;/span&gt;);
        }
    }

    &lt;span style="COLOR: blue"&gt;protected override object &lt;/span&gt;CreateBehavior()
    {
        &lt;span style="COLOR: blue"&gt;return new &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;MyCustomMessageFormatter&lt;/span&gt;();
    }
}    &lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;The next step is to let your application know about the behavior in the configuration file. This is done by adding the and "extensions" node to the configuration:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;extensions&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviorExtensions&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;CustomBehaviorElement&lt;/span&gt;"
             &lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;CustomBehaviorSample.MyCustomMessageFormatter, 
			Behavior, Version=1.0.0.0, 
			Culture=neutral, PublicKeyToken=null&lt;/span&gt;" &lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviorExtensions&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;extensions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;This tells WCF where to find the bits for your custom behavior. The name you assign here will be used when we create the behavior configuration. The type attribute is the full name of the class with all the rest of the type information WCF needs to locate and load it. In your config file is it CRUCIAL that this all be on one, non broken line. I broke it here so it would be easier to read. Also remember that spelling counts. I spent about 25 minutes trying to figure out why this didn't work for me the first time, only to discover that I had misspelled the word "neutral." &lt;/p&gt;
&lt;p&gt;So far, so good. The next step is creating the behavior configuration. &lt;/p&gt;
&lt;p&gt;Do you remember last time when I said there were two type of behaviors? Service and Endpoint Behaviors. Well, trust me, I said it. &lt;/p&gt;
&lt;p&gt;Anyway, since Service and Endpoint configurations need to be separated in our config file, this is where we need that information again. For the record, we created an Endpoint behavior, so our behavior configuration will look like this:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviors&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;endpointBehaviors&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behavior &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MyCustomEndpointBehavior&lt;/span&gt;"&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;CustomBehaviorElement&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;/&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behavior&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;endpointBehaviors&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviors&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="COLOR: blue"&gt;&lt;font face="Trebuchet MS" color="#000000"&gt;Let's contrast that with a behavior configuration for an out-of-the-box behavior:&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviors&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;serviceBehaviors&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behavior &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MEXBehaviour&lt;/span&gt;"&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;serviceMetadata &lt;/span&gt;&lt;span style="COLOR: red"&gt;httpGetEnabled&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;"&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;/&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behavior&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;                
    &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;serviceBehaviors&lt;/span&gt;&lt;/font&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;behaviors&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;Aside from the fact that one of these is an Endpoint behavior and one is a Service behavior, there aren't a lot of differences. We set a name so that we can reference the behavior elsewhere in our configuration. In our WCF-supplied MEX behavior we have a pre-defined configuration tag which supplies the configuration information for us. In the configuration for our custom behavior, we are doing the same thing, except that the behavior tag that we are using was defined by when we added the behavior type information in the behaviorExtensions section of the configuration. &lt;/p&gt;
&lt;p&gt;The other difference we see is that we are setting a property of the MEX behavior; httpGetEnabled. We have the ability to add our own custom properties and we'll do this in the next post.&lt;/p&gt;
&lt;p&gt;OK, we're almost there!&lt;/p&gt;
&lt;p&gt;All that's left is to wire up are endpoint behavior configuration:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;font size="4"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;endpoint &lt;/span&gt;&lt;span style="COLOR: red"&gt;address&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;HelloWCF&lt;/span&gt;" &lt;span style="COLOR: red"&gt;binding&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;wsHttpBinding&lt;/span&gt;" 
&lt;span style="COLOR: red"&gt;	contract&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;CustomBehaviorSample.IHelloWCF&lt;/span&gt;" 
          &lt;span style="COLOR: red"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MyCustomEndpointBehavior&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;And that's pretty much it. If we run it, we get the result we expect:&lt;/p&gt;
&lt;p&gt; &lt;img style="WIDTH: 426px; HEIGHT: 162px" height="162" alt="See, it worked!" width="401" src="http://jamescbender.com/bendersblog/images/blog/haha.png" /&gt;&lt;/p&gt;
&lt;p&gt;Easy peasy! But, that message is hard coded into our behavior, and I don't really like that. We'll fix that in the next post...&lt;/p&gt;&lt;img src="http://jamescbender.com/bendersblog/aggbug/10.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>James Bender</dc:creator>
            <guid>http://jamescbender.com/bendersblog/archive/2008/03/01/making-wcf-quotbehavequot---part-three.aspx</guid>
            <pubDate>Sat, 01 Mar 2008 15:29:03 GMT</pubDate>
            <wfw:comment>http://jamescbender.com/bendersblog/comments/10.aspx</wfw:comment>
            <comments>http://jamescbender.com/bendersblog/archive/2008/03/01/making-wcf-quotbehavequot---part-three.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://jamescbender.com/bendersblog/comments/commentRss/10.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>