Rory Primrose

Learn from my mistakes, you don't have time to make them yourself

View project on GitHub

Mixed WCF endpoint bindings for hosted workflow services

I am working on a project where I have multiple hosted WF services. All the services were secured using federated security with WIF and a custom STS. This has all worked fine until I added a new service workflow that needed to be accessible by anonymous users. This is where things get a little tricky.

The WCF configuration for the hosted services looked a little like this before the anonymous service was added.

        <add scheme=&quot;http&quot;
                binding=&quot;ws2007FederationHttpBinding&quot; />
                <security mode=&quot;TransportWithMessageCredential&quot;>
                    <message establishSecurityContext=&quot;false&quot;>
                        <issuerMetadata address=&quot;https://localhost/JabiruSts/Service.svc/mex&quot; />
                            <!--Following are the claims offered by STS 'https://localhost/JabiruSts/Service.svc'. Add or uncomment claims that you require by your application and then update the federation metadata of this application.-->
                            <add claimType=&quot;;
                                    isOptional=&quot;true&quot; />
                            <add claimType=&quot;;
                                    isOptional=&quot;true&quot; />
                <federatedServiceHostConfiguration />
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled=&quot;true&quot; />
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults=&quot;true&quot; />
                    <serviceCertificate findValue=&quot;DefaultApplicationCertificate&quot;
                                        x509FindType=&quot;FindBySubjectName&quot; />
                <errorHandler type=&quot;Neovolve.Jabiru.Server.Services.FaultHandler, Neovolve.Jabiru.Server.Services&quot; />
            <add name=&quot;errorHandler&quot;
                    type=&quot;Neovolve.Toolkit.Communication.ErrorHandlerElement, Neovolve.Toolkit&quot; />
            <add name=&quot;federatedServiceHostConfiguration&quot;
                    type=&quot;Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement, Microsoft.IdentityModel, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot; />
    <serviceHostingEnvironment multipleSiteBindingsEnabled=&quot;true&quot; />

The key thing to notice is that WCF4 uses default configuration values. These services use ws2007FederationHttpBinding in order to communicate with the STS but this is not the default binding for the HTTP stack. The configuration makes this work by defining the federation binding for HTTP using the protocolMapping/add element. The bindings/ws2007FederationBinding configuration does not specify a name as it represents the default configuration for that type of binding.

I attempted to modify this configuration with an explicit service configuration for my anonymous service that uses an IRegistration contract. There were a few roadblocks along the way, but here are the tips to get you across the line.

The first step is to define a configuration name against the xamlx file. This is accessed by viewing the properties of the workflow (the workflow, not any child activity).image

This configuration name needs to match to a WCF service configuration name. This configuration can then define a different binding than the default for the HTTP stack. It can then also define the behaviour to use for that endpoint binding.

The relevant change to the above configuration is to add the following.

    <service name=&quot;Neovolve.Jabiru.Server.Services.Registration&quot;>
        <endpoint binding=&quot;basicHttpBinding&quot;
            contract=&quot;IRegistration&quot; />
        <binding name=&quot;SecureBasicHttpBindingConfig&quot;>
            <security mode=&quot;Transport&quot;></security>

The second important step is to define the “correct” contract name. Ordinarily the contract name in WCF would be the [Namespace].[TypeName] value of the service contract. For some reason this only worked when I specified just the type name.

My hosted workflow services can now respond to a mix of endpoint bindings for the service.

Written on November 4, 2010