Click here to Skip to main content
15,892,059 members
Articles / DevOps / Load Testing

VirtualService for ESB

Rate me:
Please Sign up or sign in to vote.
4.90/5 (32 votes)
19 Feb 2008CPOL37 min read 96.9K   1.2K   98  
This article describes the design, implementation, and usage of VirtualService for the Enterprise Service Bus, using the Microsoft .NET FX 3.5 technology.
//*****************************************************************************
//    Description.....WS-Transfer Activity
//                                
//    Author..........Roman Kiss, rkiss@pathcom.com
//    Copyright © 2007 ATZ Consulting Inc. (see included license.rtf file)        
//                        
//    Date Created:    07/12/07
//
//    Date        Modified By     Description
//-----------------------------------------------------------------------------
//    07/12/07    Roman Kiss     Initial Revision
//*****************************************************************************
//
#region Namespaces
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections.Generic;
using System.Collections;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
//
using RKiss.ESB;
using RKiss.WSTransfer;
#endregion

namespace RKiss.WSTransferActivity
{
    [ToolboxItem(typeof(ActivityToolboxItem))]
    [Designer(typeof(WSRTActivityDesigner), typeof(IDesigner))]
    public partial class WSRT_Mex : Activity
    {
        public WSRT_Mex()
        {
            InitializeComponent();
        }

        protected override void InitializeProperties()
        {
            base.InitializeProperties();
        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {

            // intercept before the processing
            base.RaiseEvent(WSRT_Mex.InvokingEvent, this, EventArgs.Empty);

            if (string.IsNullOrEmpty(Wsdl))
            {
                if (OperationContext.Current != null)
                {
                    ServiceConfigDataService service = OperationContext.Current.Host.Extensions.Find<ServiceConfigDataService>();
                    Wsdl = service.ServiceConfigData.Wsdl;
                }
                else
                {
                    throw new InvalidOperationException(string.Format("The {0} activity must run within the ReceiveActivity - valid OperationContext.Current", this.Name));
                }
                if (string.IsNullOrEmpty(Wsdl))
                {
                    throw new ArgumentException("Missing wsdl metadata in the config");
                }
            }

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            if (Wsdl.Trim().StartsWith("<"))
                doc.LoadXml(Wsdl);
            else
                doc.Load(Wsdl);

            GetResponse response = new GetResponse(false);
            response.Resource = doc.DocumentElement;
            MessageResponse = response.CreateMessage();
                      
            // done
            return ActivityExecutionStatus.Closed;
        }

        #region Properties
        public static DependencyProperty MessageRequestProperty = DependencyProperty.Register("MessageRequest", typeof(Message), typeof(WSRT_Mex));

        [DescriptionAttribute("UnTyped Message Request")]
        [CategoryAttribute("Message")]
        [BrowsableAttribute(true)]
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        public Message MessageRequest
        {
            get
            {
                return ((Message)(base.GetValue(WSRT_Mex.MessageRequestProperty)));
            }
            set
            {
                base.SetValue(WSRT_Mex.MessageRequestProperty, value);
            }
        }

        public static DependencyProperty MessageResponseProperty = DependencyProperty.Register("MessageResponse", typeof(Message), typeof(WSRT_Mex));

        [DescriptionAttribute("UnTyped Message Response")]
        [CategoryAttribute("Message")]
        [BrowsableAttribute(true)]
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        public Message MessageResponse
        {
            get
            {
                return ((Message)(base.GetValue(WSRT_Mex.MessageResponseProperty)));
            }
            set
            {
                base.SetValue(WSRT_Mex.MessageResponseProperty, value);
            }
        }

        public string Wsdl { get; set; }
        #endregion

        #region Handlers
        public static DependencyProperty InvokingEvent = DependencyProperty.Register("Invoking", typeof(EventHandler), typeof(WSRT_Mex));

        [Description("Please specify the method to be called before the activity is executed")]
        [Category("Handlers")]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public event EventHandler Invoking
        {
            add
            {
                base.AddHandler(WSRT_Mex.InvokingEvent, value);
            }
            remove
            {
                base.RemoveHandler(WSRT_Mex.InvokingEvent, value);
            }
        }
        #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