Click here to Skip to main content
15,884,472 members
Articles / Hosted Services / Azure

RoutingService on Azure

Rate me:
Please Sign up or sign in to vote.
4.89/5 (10 votes)
18 Jul 2011CPOL19 min read 59.8K   429   20  
This article describes a design, implementation and usage of the WCF4 Routing Service hosted by Windows Azure.
//*****************************************************************************
//    Description.....Null Transport 
//                                
//    Author..........Roman Kiss, rkiss@pathcom.com
//    Copyright © 2007 ATZ Consulting Inc.  (see included license.rtf file)     
//                        
//    Date Created:    07/07/07
//
//    Date        Modified By     Description
//-----------------------------------------------------------------------------
//    07/07/07    Roman Kiss     Initial Revision
//    04/04/11    Roman Kiss     Modify for workflow channel
//    07/07/11    Roman Kiss     Modify for azure channel
//*****************************************************************************
//  
#region Namespaces
using System;
using System.Activities;
using System.Diagnostics;
using System.ServiceModel;
using System.ServiceModel.Channels;
using RKiss.CustomChannels.Common;
#endregion


namespace RKiss.WorkflowChannel
{
    internal class WorkflowOutputChannel : OutputChannelBase, IOutputChannel
    {
        string connectionString = null;
        string trackingProfileName = null;

        #region Constructors
        internal WorkflowOutputChannel(ChannelManagerBase factory, EndpointAddress remoteAddress, Uri via)
            : base(factory, remoteAddress, via)
        {
            Trace.TraceInformation("WorkflowOutputChannel, remoteAddress={0}", remoteAddress);

            this.connectionString = (factory as WorkflowChannelFactory<IOutputChannel>).WorkflowTransportBindingElement.RepositorySettingName;
            this.trackingProfileName = (factory as WorkflowChannelFactory<IOutputChannel>).WorkflowTransportBindingElement.TrackingProfileName;
        }
        #endregion

        #region Send
        public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state)
        {   
             // double check
            base.ThrowIfDisposedOrNotOpen();

            // add remote address to the message header
            base.RemoteAddress.ApplyTo(message);

            // load and create instance of workflow
            WorkflowApplication wfa = WfHelper.CreateWorkflowApplication(message, this.connectionString, trackingProfileName);

            return wfa.BeginRun(timeout, callback, state);
        }
        public IAsyncResult BeginSend(Message message, AsyncCallback callback, object state)
        {
            return BeginSend(message, base.DefaultSendTimeout, callback, state);
        }
        public void EndSend(IAsyncResult result)
        {
             WfHelper.EndRun(result);
        }
        public void Send(Message message)
        {
            Send(message, base.DefaultSendTimeout);
        }
        public void Send(Message message, TimeSpan timeout)
        {
             // double check
            base.ThrowIfDisposedOrNotOpen();

            // add remote address to the message header
            base.RemoteAddress.ApplyTo(message);

            // load and invoke a workflow activity in synch manner (the same thread!)
            WfHelper.WorkflowInvoker(message, this.connectionString, timeout, trackingProfileName);
        }
        #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