Exemple #1
0
 /// <summary>
 /// Close the specified service channel.
 /// </summary>
 /// <param name="channel">The channel to close.</param>
 /// <param name="abort">Whether the close should be an abort.</param>
 private static void CloseChannel(IContextChannel channel, bool abort)
 {
     if (channel != null)
     {
         if (abort)
         {
             channel.Abort();
         }
         else
         {
             channel.Close();
         }
     }
 }
Exemple #2
0
 public void CloseChannel()
 {
     if (_channelCache != null)
     {
         if (_channelCache.State == CommunicationState.Opened)
         {
             _channelCache.Close();
         }
         else if (_channelCache.State == CommunicationState.Faulted)
         {
             _channelCache.Abort();
         }
         _channelCache.Closed  -= Channel_Closed;
         _channelCache.Opened  -= Channel_Opened;
         _channelCache.Faulted -= Channel_Faulted;
     }
 }
Exemple #3
0
 /// <summary>
 /// Closes the channel
 /// </summary>
 private void Close()
 {
     try
     {
         System.Diagnostics.Trace.WriteLine("Closing channel '" + typeof(T).Name + "'");
         // Access m_Channel directly because accessing Channel can cause stack overflow
         if (m_Channel != null)
         {
             // Kill existing channel
             m_Channel.Faulted -= new EventHandler(Channel_Faulted);
             try
             {
                 m_Channel.Close(TimeSpan.FromMilliseconds(100));
             }
             catch (Exception ex)
             {
                 System.Reflection.MethodBase mb = System.Reflection.MethodBase.GetCurrentMethod();
                 System.Diagnostics.Trace.WriteLine(ex.Message, string.Format("{0}.{1}.{2}", mb.DeclaringType.Namespace, mb.DeclaringType.Name, mb.Name));
                 try
                 {
                     m_Channel.Abort();
                 }
                 catch
                 {
                     // No-op
                 }
             }
         }
         Channel = null;
     }
     catch (Exception ex)
     {
         System.Reflection.MethodBase mb = System.Reflection.MethodBase.GetCurrentMethod();
         System.Diagnostics.Trace.WriteLine(ex.Message, string.Format("{0}.{1}.{2}", mb.DeclaringType.Namespace, mb.DeclaringType.Name, mb.Name));
     }
 }
 public void Disconnect()
 {
     SendMessage(new HeartbeatResponse("close session"));
     Chanel.Close();
 }
Exemple #5
0
        public override void Dispatch(MessageDelivery messageDelivery)
        {
            if (!Started)
            {
                throw new InvalidOperationException("Dispatcher is not started yet");
            }
            ChannelFactory factory = CreateFactory();

            factory.Endpoint.Address = new EndpointAddress(Endpoint.Address);
            ApplySecurityContext(messageDelivery, factory);
            IContextChannel proxy = CreateProxy(factory);

            using (OperationContextScope scope = new OperationContextScope(proxy))
            {
                bool success = false;
                try
                {
                    var lookup = initActionLookup(Endpoint);

                    MethodInfo methodInfo = lookup.MethodLookup[_passThrough ? "*" : messageDelivery.Action];

                    if (methodInfo != null)
                    {
                        try
                        {
                            object result = methodInfo.Invoke(proxy, new object[] { messageDelivery.Message });

                            if (lookup.ReplyActionLookup.ContainsKey(messageDelivery.Action)) // if two way message, publish reply
                            {
                                KeyValuePair <MessageDeliveryContextKey, object>[] replyData = new KeyValuePair <MessageDeliveryContextKey, object> [1];
                                replyData[0] = new KeyValuePair <MessageDeliveryContextKey, object>(MessageDelivery.CorrelationId, GetResponseCorrelationId(messageDelivery));

                                Runtime.PublishOneWay(new PublishRequest(Endpoint.ContractType, lookup.ReplyActionLookup[messageDelivery.Action], result, new MessageDeliveryContext(replyData)));
                            }
                        }
                        catch (System.Reflection.TargetInvocationException ex)
                        {
                            if (lookup.ReplyActionLookup.ContainsKey(messageDelivery.Action)) // if two way message, publish reply
                            {
                                KeyValuePair <MessageDeliveryContextKey, object>[] replyData = new KeyValuePair <MessageDeliveryContextKey, object> [1];
                                replyData[0] = new KeyValuePair <MessageDeliveryContextKey, object>(MessageDelivery.CorrelationId, GetResponseCorrelationId(messageDelivery));

                                FaultException fex = ex.InnerException as FaultException;
                                if (fex != null)
                                {
                                    Runtime.PublishOneWay(new PublishRequest(Endpoint.ContractType, fex.Action, ((FaultException)ex.InnerException), new MessageDeliveryContext(replyData)));
                                }
                                else
                                {
                                    throw;
                                }
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("Matching method not found");
                    }
                    proxy.Close();
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        proxy.Abort();
                    }
                }
            }
        }