示例#1
0
        void IDuplexSessionRouter.ProcessMessage(Message message)
        {
            // One router service instance exists for each sessionful channel. If a channel hasn't been created yet, create one.
            if (this.duplexSessionChannel == null)
            {
                lock (this.sessionSyncRoot)
                {
                    if (this.duplexSessionChannel == null)
                    {
                        EndpointAddress forwardingAddress = this.extension.RoutingTable.SelectDestination(message);
                        if (forwardingAddress == null)
                        {
                            message.Close();
                            return;
                        }

                        ISimplexSessionRouter callbackChannel = OperationContext.Current.GetCallbackChannel <ISimplexSessionRouter>();
                        // Don't register the forwarding channel with the service instance. That way, the service instance can get disposed when the incoming channel closes, and then dispose of the forwarding channel.
                        using (new OperationContextScope((OperationContext)null))
                        {
                            ChannelFactory <IDuplexSessionRouter> factory = new DuplexChannelFactory <IDuplexSessionRouter>(new InstanceContext(null, new ReturnMessageHandler(callbackChannel)), this.extension.Bindings[forwardingAddress.Uri.Scheme], forwardingAddress);
                            // Add a channel behavior that will turn off validation of @mustUnderstand on the headers belonging to messages flowing the opposite direction.
                            factory.Endpoint.Behaviors.Add(new MustUnderstandBehavior(false));
                            this.duplexSessionChannel = factory.CreateChannel();
                        }
                    }
                }
            }

            Console.WriteLine("Forwarding message " + message.Headers.Action + "...");
            this.duplexSessionChannel.ProcessMessage(message);
        }
示例#2
0
        void ISimplexSessionRouter.ProcessMessage(Message message)
        {
            // One router service instance exists for each sessionful channel. If a channel hasn't been created yet, create one.
            if (this.simplexSessionChannel == null)
            {
                lock (this.sessionSyncRoot)
                {
                    if (this.simplexSessionChannel == null)
                    {
                        EndpointAddress forwardingAddress = this.extension.RoutingTable.SelectDestination(message);
                        if (forwardingAddress == null)
                        {
                            message.Close();
                            return;
                        }

                        // Don't register the forwarding channel with the service instance. That way, the service instance can get disposed when the incoming channel closes, and then dispose of the forwarding channel.
                        using (new OperationContextScope((OperationContext)null))
                        {
                            ChannelFactory <ISimplexSessionRouter> factory = new ChannelFactory <ISimplexSessionRouter>(this.extension.Bindings[forwardingAddress.Uri.Scheme], forwardingAddress);
                            this.simplexSessionChannel = factory.CreateChannel();
                        }
                    }
                }
            }

            Console.WriteLine("Forwarding message " + message.Headers.Action + "...");
            this.simplexSessionChannel.ProcessMessage(message);
        }
示例#3
0
 public ReturnMessageHandler(ISimplexSessionRouter returnChannel)
 {
     this.returnChannel = returnChannel;
 }