Search code examples
.netwcfbiztalkbiztalk-2010machine.config

How to add custom WCF behavior extension to machine.config


I'm trying to implement my own version of the Custom Behavior shown here: Using Windows Credentials in WCF-Custom adapter and here: Impersonate WCF Credentials when calling a WCF Service

BizTalk requires everything to be put in the GAC, which I did by running GacUtil.

I attempted the following changes to machine.config, and I know they didn't work because if I restart the BizTalk Host Instance, I get bizarre errors.

Changed from this:

  <section name="extensions" type="System.ServiceModel.Configuration.ExtensionsSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

To this:

  <section name="extensions" type="System.ServiceModel.Configuration.ExtensionsSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <add name="WindowsCredentialsBehaviour" type="MyApp.Biztalk.WCF.Extensions.ImpersonateBasicCredentialsBehaviour, MyApp.CustomEndpointBehavior, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b12735283a466be4" />
  </section>

In BizTalk, the Assembly looks like this:

MyApp.CustomEndpointBehavior, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b12735283a466be4"

So I have two main questions:

  1. I'm not sure why in the config file there are two names, is one the class or behavior name, and the second is the assembly name?
  2. What did I do wrong?

Here are my namespaces:

namespace MyApp.Biztalk.WCF.Extensions
{
    public class ImpersonateBasicCredentialsBehaviour : IEndpointBehavior
...
namespace MyApp.Biztalk.WCF.Extensions
{
    public class ImpersonateBasicCredentialsBehaviourElement : BehaviorExtensionElement
...

I also tried to edit machine.config with the SDK tool: SvcConfigEditor.exe, but it gave this error, so I was left to edit in NotePad++.

enter image description here


Solution

  • You don't need to define your section (it's already defined). Instead, you just configure your extension in the machine level configuration:

    <system.serviceModel>
        <extensions>
            <behaviorExtensions>
                <add name="WindowsCredentialsBehaviour" type="MyApp.Biztalk.WCF.Extensions.ImpersonateBasicCredentialsBehaviour, Asurion.CustomEndpointBehavior" />
            </behaviorExtensions>
        </extensions>
    </system.serviceModel>
    

    It will then merge with any application's configuration file that utilizes WCF (system.serviceModel). You just need to make sure the type MyApp.Biztalk.WCF.Extensions.ImpersonateBasicCredentialsBehaviour is in the assembly available to an application that wants to use WCF (either in GAC or in a private bin path).