当前位置: 首页>>代码示例>>C#>>正文


C# DuplexChannelFactory.Abort方法代码示例

本文整理汇总了C#中DuplexChannelFactory.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# DuplexChannelFactory.Abort方法的具体用法?C# DuplexChannelFactory.Abort怎么用?C# DuplexChannelFactory.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DuplexChannelFactory的用法示例。


在下文中一共展示了DuplexChannelFactory.Abort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid

    public static void RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid()
    {
        DuplexChannelFactory<IWcfDuplexService> factory = null;
        Guid guid = Guid.NewGuid();

        NetHttpBinding binding = new NetHttpBinding();
        binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;

        WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback();
        InstanceContext context = new InstanceContext(callbackService);

        try
        {
            factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpWebSocketTransport_Address));
            IWcfDuplexService duplexProxy = factory.CreateChannel();

            Task.Run(() => duplexProxy.Ping(guid));
            Guid returnedGuid = callbackService.CallbackGuid;

            Assert.True(guid == returnedGuid, string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid));
        }
        finally
        {
            if (factory != null && factory.State != CommunicationState.Closed)
            {
                factory.Abort();
            }
        }
    }
开发者ID:dmetzgar,项目名称:wcf,代码行数:29,代码来源:WebSocketTests.cs

示例2: ServiceContract_TypedProxy_AsyncTask_CallbackReturn

    public static void ServiceContract_TypedProxy_AsyncTask_CallbackReturn()
    {
        DuplexChannelFactory<IWcfDuplexTaskReturnService> factory = null;
        Guid guid = Guid.NewGuid();

        NetTcpBinding binding = new NetTcpBinding();
        binding.Security.Mode = SecurityMode.None;

        DuplexTaskReturnServiceCallback callbackService = new DuplexTaskReturnServiceCallback();
        InstanceContext context = new InstanceContext(callbackService);

        try
        {
            factory = new DuplexChannelFactory<IWcfDuplexTaskReturnService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address));
            IWcfDuplexTaskReturnService serviceProxy = factory.CreateChannel();

            Task<Guid> task = serviceProxy.Ping(guid);

            Guid returnedGuid = task.Result;

            Assert.Equal(guid, returnedGuid);

            factory.Close();
        }
        finally
        {
            if (factory != null && factory.State != CommunicationState.Closed)
            {
                factory.Abort();
            }
        }
    }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:32,代码来源:TypedProxyDuplexTests.cs

示例3: CreateChannel_EndpointAddress_Null_Throws

    public static void CreateChannel_EndpointAddress_Null_Throws()
    {
        WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
        InstanceContext context = new InstanceContext(callback);
        Binding binding = new NetTcpBinding();
        EndpointAddress remoteAddress = null;

        DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, remoteAddress);
        try {
            Assert.Throws<InvalidOperationException>(() =>
               {
                   factory.Open();
                   factory.CreateChannel();
               });
        }
        finally
        { 
            factory.Abort();
        }
    }
开发者ID:wl0240407225,项目名称:wcf,代码行数:20,代码来源:DuplexChannelFactoryTest.cs

示例4: worker

        internal static void worker(int loop, string name, InstanceContext context)
        {
            //ThreadPool.QueueUserWorkItem(delegate
            //{
                DuplexChannelFactory<ITest> factory = null;
                ITest channel = null;
                try
                {
                    factory = new DuplexChannelFactory<ITest>(context, name);

                    channel = factory.CreateChannel();

                    using (var scope = new OperationContextScope((IContextChannel)channel))
                    {
                        OperationContext.Current.OutgoingMessageHeaders.ReplyTo = ((IClientChannel)channel).LocalAddress;
                        
                        // action
                        channel.Ping("Hello,  " + loop.ToString());

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine(string.Format("[{0}, {1}]: D O N E, tid={2}", loop, name, Thread.CurrentThread.GetHashCode()));
                        Console.ResetColor();

                        Console.WriteLine("\n+++ press any key to close this channel +++\n");
                        Console.ReadLine();
                    }

                    ((IChannel)channel).Close();
                    factory.Close();
                }
                catch (Exception ex)
                {
                    if (channel != null) ((IChannel)channel).Abort();
                    if (factory != null) factory.Abort();
                    Console.WriteLine(ex.Message);
                }
            //});
        }
开发者ID:MatthewChudleigh,项目名称:solipsist,代码行数:38,代码来源:Program.cs

示例5: ServiceContract_TypedProxy_DuplexCallback

    public static void ServiceContract_TypedProxy_DuplexCallback()
    {
        DuplexChannelFactory<IDuplexChannelService> factory = null;
        StringBuilder errorBuilder = new StringBuilder();
        Guid guid = Guid.NewGuid();

        try
        {
            NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;

            DuplexChannelServiceCallback callbackService = new DuplexChannelServiceCallback();
            InstanceContext context = new InstanceContext(callbackService);

            factory = new DuplexChannelFactory<IDuplexChannelService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_DuplexCallback_Address));
            IDuplexChannelService serviceProxy = factory.CreateChannel();

            serviceProxy.Ping(guid);
            Guid returnedGuid = callbackService.CallbackGuid;

            if (guid != returnedGuid)
            {
                errorBuilder.AppendLine(String.Format("The sent GUID does not match the returned GUID. Sent: {0} Received: {1}", guid, returnedGuid));
            }

            factory.Close();
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString()));
            for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException)
            {
                errorBuilder.AppendLine(String.Format("Inner exception: {0}", innerException.ToString()));
            }
        }
        finally
        {
            if (factory != null && factory.State != CommunicationState.Closed)
            {
                factory.Abort();
            }
        }

        if (errorBuilder.Length != 0)
        {
            Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: ServiceContract_TypedProxy_DuplexCallback FAILED with the following errors: {0}", errorBuilder));
        }
    }
开发者ID:TerabyteX,项目名称:wcf,代码行数:48,代码来源:TypedProxyTests.cs

示例6: Main

        static void Main()
        {
            _handler += Handler;
            SetConsoleCtrlHandler(_handler, true);
            ClientProcessor = new ClientProcessor();

            var instanceContext = new InstanceContext(new BombermanCallbackService(ClientProcessor));
            Binding binding = new NetTcpBinding(SecurityMode.None);
            DuplexChannelFactory<IBombermanService> factory = new DuplexChannelFactory<IBombermanService>(instanceContext, binding, new EndpointAddress(
                new Uri(string.Concat("net.tcp://", ConfigurationManager.AppSettings["MachineName"], ":7900/BombermanCallbackService"))));
            Proxy = factory.CreateChannel();

            Console.WriteLine("--------------------------------------");
            Console.WriteLine("-------- Welcome to Bomberman --------");
            Console.WriteLine("--------------------------------------\n\n");

            do
            {
                Console.WriteLine("Type your player name :\n");
                Username = Console.ReadLine();
                ConnectUser(Username);
                ClientProcessor.Username = Username;
            } while (ErrorConnection);

            Log.Initialize(@"D:\Temp\BombermanLogs", "Client_" + Username + ".log");
            Log.WriteLine(Log.LogLevels.Info, "Logged at " + DateTime.Now.ToShortTimeString());

            bool stop = false;
            while (!stop)
            {
                ConsoleKeyInfo keyboard = Console.ReadKey();
                switch (keyboard.Key)
                {
                    //s
                    case ConsoleKey.S:
                        StartGame();
                        break;
                    case ConsoleKey.UpArrow:
                        MoveTo(ActionType.MoveUp);
                        break;
                    case ConsoleKey.LeftArrow:
                        MoveTo(ActionType.MoveLeft);
                        break;
                    case ConsoleKey.RightArrow:
                        MoveTo(ActionType.MoveRight);
                        break;
                    case ConsoleKey.DownArrow:
                        MoveTo(ActionType.MoveDown);
                        break;
                    case ConsoleKey.X: // SinaC: never leave a while(true) without an exit condition
                        stop = true;
                        break;
                }
            }

            // SinaC: Clean properly factory
            try
            {
                factory.Close();
            }
            catch (Exception ex)
            {
                Log.WriteLine(Log.LogLevels.Warning, "Exception:{0}", ex);
                factory.Abort();
            }
        }
开发者ID:KevinVDF,项目名称:Bomberman,代码行数:66,代码来源:Program.cs


注:本文中的DuplexChannelFactory.Abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。