Esempio n. 1
0
        static void Main(string[] args)
        {
            string path = @".\private$\XactQueue4Demo";

            if (!MessageQueue.Exists(path))
            {
                MessageQueue.Create(path, true);
            }
            var queue = new MessageQueue(path);

            queue.Purge();

            using (ChannelFactory <IGreeting> channelFactoryHello = new ChannelFactory <IGreeting>("greetingService"))
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    IGreeting proxy = channelFactoryHello.CreateChannel();
                    proxy.SayHello("Foo");
                    proxy.SayGoodbye("Bar");
                    (proxy as ICommunicationObject).Close();
                    scope.Complete();
                }
            }
            var message = queue.Receive();

            byte[] buffer = new byte[message.BodyStream.Length];
            message.BodyStream.Read(buffer, 0, buffer.Length);
            Console.WriteLine(Encoding.Default.GetString(buffer));
        }
    public string SayHello(string strLanguage)
    {
        var language = languageFactory.Create(strLanguage);

        greeting = greetingFactory.Create(language);
        return(greeting.SayHello());
    }
Esempio n. 3
0
 static void Main(string[] args)
 {
     using (ChannelFactory <IGreeting> channelFactoryHello = new ChannelFactory <IGreeting>("greetingService"))
     {
         using (TransactionScope scope = new TransactionScope())
         {
             IGreeting proxy = channelFactoryHello.CreateChannel();
             proxy.SayHello("Foo");
             proxy.SayGoodbye("Bar");
             (proxy as ICommunicationObject).Close();
             scope.Complete();
         }
     }
 }