Exemplo n.º 1
0
        InstanceContext CreateInstanceContext(MessageProcessingContext mrc)
        {
            InstanceContext          iCtx            = null;
            DispatchRuntime          dispatchRuntime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
            IInstanceContextProvider p = dispatchRuntime.InstanceContextProvider;

            if (p != null)
            {
                iCtx = p.GetExistingInstanceContext(mrc.IncomingMessage, mrc.OperationContext.Channel);
            }
            if (iCtx == null)
            {
                ServiceHostBase host = dispatchRuntime.ChannelDispatcher.Host;
                iCtx = new InstanceContext(dispatchRuntime.ChannelDispatcher.Host, null, false);
                // FIXME: could be easier way to identify session channel
                if ((mrc.Channel is ISessionChannel <IInputSession> || mrc.Channel is ISessionChannel <IDuplexSession>) && host.Description.Behaviors.Find <ServiceBehaviorAttribute> ().InstanceContextMode == InstanceContextMode.PerSession)
                {
                    mrc.Channel.Closed += delegate { iCtx.Close(); }
                }
                ;
            }

            iCtx.InstanceManager = new InstanceManager(dispatchRuntime);
            return(iCtx);
        }
    }
Exemplo n.º 2
0
 public void OffLine()
 {
     client.Unsubscribe();
     //client.OffLine("黄埔");
     instanceContext.Abort();
     instanceContext.Close();
     client.Abort();
     client.Close();
 }
        public void InitializeInstanceContext(InstanceContext instanceContext, Message message, IContextChannel channel)
        {
            var key = channel.SessionId ?? String.Empty;

            pool [key]      = instanceContext;
            channel.Closed += delegate {
                pool.Remove(key);
                instanceContext.Close();                  // FIXME: timeout?
            };
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            ServiceHost host = null;

            try
            {
                using (host = new ServiceHost(typeof(Test)))
                {
                    host.Open();

                    Thread.Sleep(2500);
                    Console.WriteLine("\npress any key to continue ...\n");
                    Console.ReadLine();

                    var testCallback = new TestCallback();
                    var context      = new InstanceContext(testCallback);

                    // action
                    worker(1234567890, "gaga", context);

                    Console.WriteLine("\n+++ press any key to close a ServiceHost +++\n");
                    Console.ReadLine();

                    context.Close();
                    host.Close();
                }
            }
            catch (CommunicationException ex)
            {
                if (host != null)
                {
                    host.Abort();
                }

                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                if (host != null)
                {
                    host.Abort();
                }

                Console.WriteLine(ex);
                Console.ReadLine();
            }
            finally
            {
                Console.WriteLine("\n*** press any key to exit ... ***\n");
                Console.ReadLine();
            }
        }
Exemplo n.º 5
0
        protected override void OnClosed(EventArgs e)
        {
            try
            {
                if (_client != null)
                {
                    _client.Close();
                }

                if (NetContext != null)
                {
                    NetContext.Close();
                }
            }
            catch { }

            base.OnClosed(e);
        }
 private void Context_Faulted(object sender, System.EventArgs e)
 {
     Log.InfoFormat("----- Context_Faulted -----");
     context.Close();
     IsConnected = false;
 }