Click here to Skip to main content
15,886,199 members
Articles / Web Development / IIS

MEF and Workflow Services Integration

Rate me:
Please Sign up or sign in to vote.
4.83/5 (9 votes)
1 Jan 2011CPOL6 min read 34.9K   442   26  
Building up activities using the Managed Extensibility Framework for workflow services hosted in IIS.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel.Activities;
using BaseLibrary;
using System.ServiceModel.Channels;

namespace BaseLibrary
{
    public abstract class MefWorkflowProviderExtensionBehavior : IServiceBehavior
    {      
        /// <summary>
        /// Where the magic happens and your extension gets added to the workflow service host
        /// </summary>
        /// <param name="serviceDescription"></param>
        /// <param name="serviceHostBase"></param>
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            WorkflowServiceHost host = serviceHostBase as WorkflowServiceHost;
            if (host != null)
            {
                // register the mef provider
                host.WorkflowExtensions.Add(GetProvider());

                // register a error handler on the channel dispatchers
                foreach (ChannelDispatcher cd in host.ChannelDispatchers)
                {
                    cd.ErrorHandlers.Add(new WorkflowUnhandledException());
                }
            }
        }

        protected abstract MefWorkflowProvider GetProvider();

        public virtual void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) { }
        public virtual void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer NBN International
United Kingdom United Kingdom
I am Gareth, working in the book industry specializing in EDI and B2B integration. Starting out as a child bashing out programs on the old commodore 64, I have since progressed from VB6 through the .net framework and loving c#, wf, wpf and where these are heading... hoping one day to have the excuse to play with silverlight.

Comments and Discussions