Click here to Skip to main content
15,887,596 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.8K   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.
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
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.Channels;
using System.Runtime.Serialization;
using System.Xml;
using System.IO;
//
using RKiss.WSTransfer;

namespace WorkflowLibrary1
{
	public partial class Workflow5 : SequentialWorkflowActivity
	{
        public System.ServiceModel.Channels.Message _message = default(System.ServiceModel.Channels.Message);
        public System.ServiceModel.Channels.Message _returnValue = default(System.ServiceModel.Channels.Message);

        private void InMessage(object sender, EventArgs e)
        {
            Console.WriteLine("\n **** ProcessMessage - mediation IN ****");
            Console.WriteLine("\n" + _message);
        }

        private void ProcessMessage(object sender, EventArgs e)
        {
            Console.WriteLine("\n **** Invoking Business ****\n");
        }

        private void OutMessage(object sender, EventArgs e)
        {
            Console.WriteLine("\n **** ProcessMessage - mediation OUT ****");
            
            // post-processing
            List<AddressHeader> list = new List<AddressHeader>();
            list.Add(AddressHeader.CreateAddressHeader(ResourceDescriptor.DataContractName, ResourceDescriptor.DataContractNamespace, new ResourceDescriptor()));
            AddressHeaderCollection ahc = new AddressHeaderCollection(new AddressHeaderCollection(list));
            Uri uriTo = OperationContext.Current.IncomingMessageHeaders.To;
            EndpointAddress resourceEndpointAddress = new EndpointAddress(uriTo, (EndpointIdentity)null, ahc);

            // create stream
            MemoryStream ms = new MemoryStream();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            XmlWriter xw = XmlWriter.Create(ms, settings);
            resourceEndpointAddress.WriteTo(AddressingVersion.WSAddressing10, xw, WSTransfer.ElementNames.ResourceCreated, WSTransfer.NamespaceUri);
            xw.Flush();
            ms.Position = 0;

            // create message body from stream
            XmlDictionaryReader xdr = XmlDictionaryReader.CreateTextReader(ms, XmlDictionaryReaderQuotas.Max);
            _returnValue = Message.CreateMessage(MessageVersion.Default, WSTransfer.CreateResponseAction, xdr);

            MessageHeader hdr = MessageHeader.CreateHeader(WSResourceTransfer.ElementNames.ResourceTransfer, WSResourceTransfer.NamespaceUri, null);
            _returnValue.Headers.Add(hdr);           
        }
    }
}

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