Click here to Skip to main content
15,896,278 members
Articles / Programming Languages / XML

WS-Transfer Service for Workflow

Rate me:
Please Sign up or sign in to vote.
4.93/5 (16 votes)
23 Nov 2006CPOL12 min read 96K   438   62  
This article describes a design and implementation of the WF workflow connectivity to the Windows Communication Foundation (WCF) Service for WS-Transfer operation contract.
//*****************************************************************************
//    Description.....WCFFilters - Pipeline of the Message Filters
//                                
//    Author..........Roman Kiss, rkiss@pathcom.com
//    Copyright � 2005 ATZ Consulting Inc. - see license.rtf file      
//                        
//    Date Created:    05/05/06
//
//    Date        Modified By     Description
//-----------------------------------------------------------------------------
//    05/05/06    Roman Kiss     Initial Revision
//    07/07/06    Roman Kiss     migrating to JuneCTP 
//*****************************************************************************
//  
#region References
using System;
using System.Configuration;
using System.Collections.Specialized;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Configuration;
using System.Reflection;
#endregion


namespace RKiss.Filters
{
    /// <summary>
    /// Base class for filter
    /// </summary>
    public abstract class FilterBase
    {
        #region Properties
        HybridDictionary _properties;
        public HybridDictionary Properties
        {
            get { return _properties; }
        }
        #endregion

        #region Constructors
        protected FilterBase() : this(null)
        {
        }
        protected FilterBase(HybridDictionary properties)
        {
            _properties = properties;
        }
        #endregion

        public abstract bool ProcessMessage(ref Message message); 
    }
  
    /// <summary>
    /// Configuration object - Filter  
    /// </summary>
    [Serializable]
    public class Filter : HybridDictionary, IXmlSerializable
    {
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private Type _type;
        public Type Type
        {
            get { return _type; }
            set { _type = value; }
        }

        #region Constructors
        public Filter()
        {
        }
        public Filter(XmlReader reader)
        {
            ReadXml(reader);
        }
        #endregion

        #region IXmlSerializable Members
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsStartElement("Filter"))
            {
                this.Name = reader.GetAttribute("name");
                this.Type = Type.GetType(reader.GetAttribute("type"));
                if (reader.HasAttributes)
                {
                    reader.MoveToFirstAttribute();
                    do
                    {
                        base.Add(reader.Name, reader.Value);
                    }
                    while (reader.MoveToNextAttribute());
                }
                reader.ReadElementString();
            }
            else
            {
                throw new Exception(string.Format("Failed at element {0}, expected element is {1}", reader.Name, "Filter"));
            }
        }
        public void WriteXml(XmlWriter writer)
        {
            throw new Exception("The method or operation is not implemented.");
        }
        #endregion
    }

    /// <summary>
    /// Configuration object - List of Input Filters  
    /// </summary>
    [Serializable]
    public class InputFilters : List<Filter>, IXmlSerializable
    {
        #region Constructors
        public InputFilters()
        {       
        }
        public InputFilters(XmlReader reader)
        {
            ReadXml(reader);
        }
        #endregion

        #region IXmlSerializable Members
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsStartElement("InputFilters"))
            {
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    reader.ReadToDescendant("Filter");
                    base.Add(new Filter(reader));
                    reader.MoveToContent();
                }
                reader.ReadEndElement();
            }
            else
            {
                throw new Exception(string.Format("Failed at element {0}, expected element is {1}", reader.Name, "InputFilters"));
            }
        }
        public void WriteXml(XmlWriter writer)
        {
            throw new Exception("The method or operation is not implemented.");
        }
        #endregion
    }

    /// <summary>
    /// Configuration object - List of Output Filters  
    /// </summary>
    [Serializable]
    public class OutputFilters : List<Filter>, IXmlSerializable
    {
        #region Constructors
        public OutputFilters()
        {
        }
        public OutputFilters(XmlReader reader)
        {
            ReadXml(reader);
        }
        #endregion

        #region IXmlSerializable Members
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsStartElement("OutputFilters"))
            {
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    reader.ReadToDescendant("Filter");
                    base.Add(new Filter(reader));
                    reader.MoveToContent();
                }
                reader.ReadEndElement();
            }
            else
            {
                throw new Exception(string.Format("Failed at element {0}, expected element is {1}", reader.Name, "OutputFilters"));
            }
        }
        public void WriteXml(XmlWriter writer)
        {
            throw new Exception("The method or operation is not implemented.");
        }
        #endregion
    }


    /// <summary>
    /// Configuration object - Pipeline  
    /// </summary>
    [Serializable]
    public class Pipeline : IXmlSerializable  
    {
        InputFilters _inputFilters;
        OutputFilters _outputFilters;

        public InputFilters InputFilters
        {
            get { return _inputFilters; }
            set { _inputFilters = value; }
        }
        public OutputFilters OutputFilters
        {
            get { return _outputFilters; }
            set { _outputFilters = value; }
        }

        #region Constructors
        public Pipeline()
        {
        }
        public Pipeline(XmlReader reader)
        {
            ReadXml(reader);
        }
        #endregion

        #region IXmlSerializable Members
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }
        public void ReadXml(XmlReader reader)
        {
            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.IsStartElement("InputFilters"))
                {
                    InputFilters filters = new InputFilters(reader);
                    string enableAttribute = reader.GetAttribute("enable");
                    if (Convert.ToBoolean(enableAttribute == null ? "true" : enableAttribute))
                        _inputFilters = filters;
                }
                else if (reader.IsStartElement("OutputFilters"))
                {
                    OutputFilters filters = new OutputFilters(reader);
                    string enableAttribute = reader.GetAttribute("enable");
                    if (Convert.ToBoolean(enableAttribute == null ? "true" : enableAttribute))
                        _outputFilters = filters;
                }
                else
                {
                    throw new Exception(string.Format("Failed at element {0}, expected elements are {1}", reader.Name, "InputFilters or OutputFilters"));  
                }
                reader.MoveToContent();
            }
            reader.ReadEndElement();            
        }
        public void WriteXml(XmlWriter writer)
        {
            throw new Exception("The method or operation is not implemented.");
        }
        #endregion
    }
}

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 (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions