Ejemplo n.º 1
0
        public ChannelWrapper()
        {
            IMessagingSystemFactory anInternalMessaging = new SynchronousMessagingSystemFactory();

            // The service receives messages via one channel (i.e. it listens on one address).
            // The incoming messages are unwrapped on the server side.
            // Therefore the client must use wrapper to send messages via one channel.
            IChannelWrapperFactory aChannelWrapperFactory = new ChannelWrapperFactory();

            myDuplexChannelWrapper = aChannelWrapperFactory.CreateDuplexChannelWrapper();


            // To connect message senders and the wrapper with duplex channels we can use the following helper class.
            IConnectionProviderFactory aConnectionProviderFactory = new ConnectionProviderFactory();
            IConnectionProvider        aConnectionProvider        = aConnectionProviderFactory.CreateConnectionProvider(anInternalMessaging);


            // Factory to create message senders.
            // Sent messages will be serialized in Xml.
            IDuplexTypedMessagesFactory aCommandsFactory = new DuplexTypedMessagesFactory();

            plusSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>();
            plusSender.ResponseReceived += (s, e) => {
                Console.WriteLine("CW.V+: " + e.ResponseMessage.Value);
            };
            // attach method handling the request
            aConnectionProvider.Connect(myDuplexChannelWrapper, plusSender, "plus"); // attach the input channel to get messages from unwrapper

            minusSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>();
            minusSender.ResponseReceived += (s, e) => {
                Console.WriteLine("CW.V-: " + e.ResponseMessage.Value);
            };
            // attach method handling the request
            aConnectionProvider.Connect(myDuplexChannelWrapper, minusSender, "minus"); // attach the input channel to get messages from unwrapper

            dotSender = aCommandsFactory.CreateDuplexTypedMessageSender <TestOutput, TestInput>();
            dotSender.ResponseReceived += (s, e) => {
                Console.WriteLine("CW.V.: " + e.ResponseMessage.Value);
            };
            // attach method handling the request
            aConnectionProvider.Connect(myDuplexChannelWrapper, dotSender, "dot"); // attach the input channel to get messages from unwrapper

            IMessagingSystemFactory aTcpMessagingSystem = new TcpMessagingSystemFactory();

            // Create output channel to send requests to the service.
            IDuplexOutputChannel anOutputChannel = aTcpMessagingSystem.CreateDuplexOutputChannel("tcp://127.0.0.1:8091/");

            // Attach the output channel to the wrapper - so that we are able to send messages
            // and receive response messages.
            // Note: The service has the coresponding unwrapper.
            myDuplexChannelWrapper.AttachDuplexOutputChannel(anOutputChannel);
        }
        public void Setup()
        {
            IMessagingSystemFactory aGlobalChannelFactory = new SynchronousMessagingSystemFactory();

            myDuplexGlobalOutputChannel = aGlobalChannelFactory.CreateDuplexOutputChannel("MainChannel");
            myDuplexGlobalInputChannel  = aGlobalChannelFactory.CreateDuplexInputChannel("MainChannel");

            myMessagingForWrapper   = new SynchronousMessagingSystemFactory();
            myMessagingForUnwrapper = new SynchronousMessagingSystemFactory();

            IChannelWrapperFactory aFactory = new ChannelWrapperFactory();

            myDuplexChannelWrapper   = aFactory.CreateDuplexChannelWrapper();
            myDuplexChannelUnwrapper = aFactory.CreateDuplexChannelUnwrapper(myMessagingForUnwrapper);
        }