Click here to Skip to main content
15,884,177 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 95.9K   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.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Xml;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Transactions;


namespace ClientApplication
{
    [XmlSerializerFormat]
    [DataContract(Name = "Request", Namespace = "urn:workflowinvoker.test")]
    public class Request
    {
        [DataMember]
        private int counter;
        public int Counter
        {
            get { return counter; }
            set { counter = value; }
        }
        [DataMember]
        private string text;
        public string Text
        {
            get { return text; }
            set { text = value; }
        }
        [DataMember]
        private DateTime timestamp;
        public DateTime Timestamp
        {
            get { return timestamp; }
            set { timestamp = value; }
        }
    }

    [ServiceContract]
    public interface IPing
    {
        [OperationContract(Action = "Ping")]
        string Ping(Request request);

        [OperationContract(Action = "Ping2")]
        string Ping2(Request request);
    }




    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                for (int ii = 0; ii < 100; ii++)
                {
                    using (ChannelFactory<IPing> pingChannel = new ChannelFactory<IPing>("Pinging"))
                    {
                        pingChannel.Open();
                        IPing ping = pingChannel.CreateChannel();
                        Request request = new Request();
                        request.Counter = ii;
                        request.Text = "This si a loopback message";
                        request.Timestamp = DateTime.Now;
                        string response = ping.Ping(request);

                        Console.WriteLine(response);

                        // test 2
                        Console.WriteLine("\nPing2 test:");
                        string response2 = ping.Ping2(request);
                        Console.WriteLine(response);

                        pingChannel.Close();
                        Console.WriteLine("\nDone, Press any key to test again");
                        Console.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.ReadLine();
        }   
    }
}

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