public void ProcessRequest(RequestContext context)
        {
            MessageHeaders headers = context.RequestMessage.Headers;

            //create new request channel if needed
            IRequestChannel requestChannel = null;

            if (!_Clients.TryGetValue(headers.To, out requestChannel))
            {
                WSHttpBinding binding = CreateBinding();
                IChannelFactory <IRequestChannel> factory = binding.BuildChannelFactory <IRequestChannel>(new BindingParameterCollection());
                factory.Open();

                requestChannel = factory.CreateChannel(new EndpointAddress(headers.To));
                requestChannel.Open();
                _Clients.Add(headers.To, requestChannel);
            }

            //forward request and send back response
            MessageContainer container = new MessageContainer();
            Message          incoming  = CopyMessage(context.RequestMessage, container, MessageDirection.Incoming);

            if ((DateTime.Now - _LastReceived).TotalMilliseconds > 1750)
            {
                _Group += 1;
            }
            container.Group = _Group;
            _LastReceived   = DateTime.Now;


            //add request to gui
            Action <int, MessageContainer> msg = new Action <int, MessageContainer>(Messages.Insert);

            this.Dispatcher.Invoke(msg, new object[] { 0, container });

            //get response
            Message responseMessage = requestChannel.Request(incoming);
            Message outgoing        = CopyMessage(responseMessage, container, MessageDirection.Outgoing);

            context.Reply(outgoing);
        }
        public Message CopyMessage(Message message, MessageContainer container, MessageDirection direction)
        {
            MessageBuffer buffer = message.CreateBufferedCopy(Int32.MaxValue);

            if (direction == MessageDirection.Incoming)
            {
                container.RequestMessageText = buffer.CreateMessage().ToString();
                container.RequestReceived = DateTime.Now;
                if (message.Properties.ContainsKey(RemoteEndpointMessageProperty.Name))
                {
                    RemoteEndpointMessageProperty property = (RemoteEndpointMessageProperty)message.Properties[RemoteEndpointMessageProperty.Name];
                    container.RemoteAddress = property.Address;
                }
                if (message.Headers.To != null)
                {
                    container.ToAddress = message.Headers.To.ToString();
                }
                container.RequestAction = message.Headers.Action;
            }
            else if(direction == MessageDirection.Outgoing)
            {
                container.ResponseMessageText = buffer.CreateMessage().ToString();
                container.ResponseReceived = DateTime.Now;
                container.ResponseAction = message.Headers.Action;
            }
            return buffer.CreateMessage();
        }
        public void ProcessRequest(RequestContext context)
        {
            MessageHeaders headers = context.RequestMessage.Headers;

            //create new request channel if needed
            IRequestChannel requestChannel = null;
            if (!_Clients.TryGetValue(headers.To, out requestChannel))
            {
                WSHttpBinding binding = CreateBinding();
                IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
                factory.Open();

                requestChannel = factory.CreateChannel(new EndpointAddress(headers.To));
                requestChannel.Open();
                _Clients.Add(headers.To, requestChannel);
            }

            //forward request and send back response
            MessageContainer container = new MessageContainer();
            Message incoming = CopyMessage(context.RequestMessage, container, MessageDirection.Incoming);
            if ((DateTime.Now - _LastReceived).TotalMilliseconds > 1750)
            {
                _Group += 1;
            }
            container.Group = _Group;
            _LastReceived = DateTime.Now;

            //add request to gui
            Action<int, MessageContainer> msg = new Action<int, MessageContainer>(Messages.Insert);
            this.Dispatcher.Invoke(msg, new object[] { 0, container });

            //get response
            Message responseMessage = requestChannel.Request(incoming);
            Message outgoing = CopyMessage(responseMessage, container, MessageDirection.Outgoing);
            context.Reply(outgoing);
        }