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


C# ChannelFactory.Close方法代码示例

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


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

示例1: Main

        internal static void Main(string[] args)
        {
            Thread.Sleep(2000);

            var binding = ReadOnly.GetBinding();
            var endpoint = new EndpointAddress(string.Concat(ReadOnly.GetProtocol(), "localhost:8080/people"));
            var factory = new ChannelFactory<IPersonService>(binding, endpoint);
            var service = factory.CreateChannel();
            var message = default(Message);

            try {
                message = service.GetPeople();

                foreach (var person in Parse(message)) {
                    Console.WriteLine(person);
                }

                ((ICommunicationObject)service).Close();
            } catch (Exception ex) {
                Trace.WriteLine(ex.Message);
                ((ICommunicationObject)service).Abort();
            } finally {
                factory.Close();
            }

            Console.ReadKey();
        }
开发者ID:naviger,项目名称:Wcf_IEnumerable_Stream,代码行数:27,代码来源:EntryPoint.cs

示例2: Run

        public async Task Run(string httpAddress, string sendToken)
        {
            var channelFactory =
                new ChannelFactory<IEchoChannel>("ServiceBusEndpoint", new EndpointAddress(httpAddress));
            channelFactory.Endpoint.Behaviors.Add(
                new TransportClientEndpointBehavior(TokenProvider.CreateSharedAccessSignatureTokenProvider(sendToken)));

            using (IEchoChannel channel = channelFactory.CreateChannel())
            {
                Console.WriteLine("Enter text to echo (or [Enter] to exit):");
                string input = Console.ReadLine();
                while (input != string.Empty)
                {
                    try
                    {
                        Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error: " + e.Message);
                    }
                    input = Console.ReadLine();
                }
                channel.Close();
            }
            channelFactory.Close();
        }
开发者ID:lokeshsp,项目名称:azure-servicebus-relay-samples,代码行数:27,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            ChannelFactory<IService> channelFactory = null;
            try
            {
                channelFactory = new ChannelFactory<IService>("Endpoint1");
                ThreadPool.QueueUserWorkItem((o) =>
                    {
                        for (int i = 1; i <= 1000; i++)
                        {
                            Console.WriteLine("{0}: invocate service! thread 1", i);
                            Console.WriteLine(channelFactory.CreateChannel().DoReturn());
                            //Thread.Sleep(1000);
                        }
                    });

                ThreadPool.QueueUserWorkItem((o) =>
                {
                    for (int i = 1; i <= 1000; i++)
                    {
                        Console.WriteLine("{0}: invocate service! thread 2", i);
                        Console.WriteLine(channelFactory.CreateChannel().DoReturn());
                        //Thread.Sleep(1000);
                    }
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                channelFactory.Close();
            }

            Console.ReadKey();
        }
开发者ID:Yuanxiangz,项目名称:WorkSpace,代码行数:34,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            Uri uri = new Uri("serial://localhost/com1");
            Console.WriteLine("Creating factory...");

            SerialTransportBinding binding = new SerialTransportBinding("COM1");

            ChannelFactory<ISerialTrasportDemo> factory =
              new ChannelFactory<ISerialTrasportDemo>(binding);

            ISerialTrasportDemo channel =
              factory.CreateChannel(new EndpointAddress(uri));

            Console.Write("Enter Text or x to quit: ");
            string message;
            while ((message = Console.ReadLine()) != "x")
            {
              string result = channel.Reflect(message);

              Console.WriteLine(
                "\nReceived for ProcessReflectRequest: " + result + "\n");
              Console.Write("Enter Text or x to quit: ");
            }

            factory.Close();
        }
开发者ID:gitlabuser,项目名称:warehouse,代码行数:26,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            try
            {
                ChannelFactory<IMyMath> factory = new ChannelFactory<IMyMath>(
                    new WSHttpBinding(),
                    new EndpointAddress("http://localhost/MyMath/Ep1")
                    );
                IMyMath channel = factory.CreateChannel();
                int a;
                string c;
                int b;
                a = Convert.ToInt32(Console.ReadLine());
                c = Console.ReadLine();
                b = Convert.ToInt32(Console.ReadLine());
                Console.ReadLine();

                int result = channel.Add(a, c, b);
                if(result == -2)
                {
                    Console.WriteLine("На нуль ділити не можна ****!!!");
                }
                Console.WriteLine("result: {0}", result);
                Console.WriteLine("Для завершения нажмите <ENTER>\n");
                Console.ReadLine();
                factory.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:RoykoSerhiy,项目名称:visualStudio_projects,代码行数:32,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(CalculatorService), new Uri(baseAddress));
            Dictionary<string, string> namespaceToPrefixMapping = new Dictionary<string, string>
            {
                { "http://www.w3.org/2003/05/soap-envelope", "SOAP12-ENV" },
                { "http://www.w3.org/2005/08/addressing", "SOAP12-ADDR" },
            };
            Binding binding = ReplacePrefixMessageEncodingBindingElement.ReplaceEncodingBindingElement(
                new WSHttpBinding(SecurityMode.None),
                namespaceToPrefixMapping);
            host.AddServiceEndpoint(typeof(ICalculator), binding, "");
            host.Open();

            Binding clientBinding = LoggingMessageEncodingBindingElement.ReplaceEncodingBindingElement(
                new WSHttpBinding(SecurityMode.None));
            ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(clientBinding, new EndpointAddress(baseAddress));
            ICalculator proxy = factory.CreateChannel();

            Console.WriteLine(proxy.Add(234, 456));

            ((IClientChannel)proxy).Close();
            factory.Close();
            host.Close();
        }
开发者ID:GusLab,项目名称:WCFSamples,代码行数:26,代码来源:Program.cs

示例7: Start

        internal void Start() 
        {
            //Create a proxy to the event service
            EndpointAddress remoteAddress = new EndpointAddress(Config.Communincation.ServiceURI);
            NetNamedPipeBinding netNamedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
            IChannelFactory<IEventService> channelFactory = new ChannelFactory<IEventService>(netNamedPipeBinding, remoteAddress);
            IEventService eventService = channelFactory.CreateChannel(remoteAddress);
            
            //Signal ready and wait for other threads to join.
            _syncStartBarrier.SignalAndWait();

            EventSource eventSource = new EventSource() { ID = Guid.NewGuid(), Name = string.Format("Publisher:{0}", _Id) };
            Console.WriteLine("{0} Running...", eventSource);

            Event @event = new Event() { Source = eventSource, Info = String.Format("EVENT PUBLISHED AT[{0}]", DateTime.Now.ToLongTimeString()), RecordedAt = DateTime.Now };
            Byte[] bytes = ProtoBufSerializer.Serialize<Event>(@event);

            //Start publishing events
            for (Int64 i = 0; i < _iterations; i++)
            {
                eventService.Handle(bytes);
            }

            channelFactory.Close();
        }
开发者ID:KrishnanSrinivasan,项目名称:Disruptor-net-v1.1.0-With-WCF,代码行数:25,代码来源:EventPublisher.cs

示例8: test_DoctorService_As_Service

 public void test_DoctorService_As_Service()
 {
     var channelFactory = new ChannelFactory<IDoctorService>("");
     var proxy = channelFactory.CreateChannel();
     (proxy as ICommunicationObject).Open();
     channelFactory.Close();
 }
开发者ID:nayan112,项目名称:HelloWorld,代码行数:7,代码来源:ServiceAccessTest.cs

示例9: Main

        static void Main(string[] args)
        {
            Console.Write("Enter the name of the user you want to connect with: ");
            string serviceUserName = Console.ReadLine();

            Uri serviceUri = new Uri(String.Format("sb://{0}/services/{1}/EchoService/", ServiceBusEnvironment.DefaultRelayHostName, serviceUserName));

            EndpointAddress address = new EndpointAddress(serviceUri);

            ChannelFactory<IEchoChannel> channelFactory = new ChannelFactory<IEchoChannel>("RelayEndpoint", address);
            IEchoChannel channel = channelFactory.CreateChannel();
            channel.Open();

            Console.WriteLine("Enter text to echo (or [Enter] to exit):");
            string input = Console.ReadLine();
            while (!String.IsNullOrEmpty(input))
            {
                try
                {
                    Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
                input = Console.ReadLine();
            }

            channel.Close();
            channelFactory.Close();
        }
开发者ID:julid29,项目名称:confsamples,代码行数:31,代码来源:Program.cs

示例10: Run

        static void Run()
        {
            MsmqIntegrationBinding binding = new MsmqIntegrationBinding();
            binding.Security.Mode = MsmqIntegrationSecurityMode.None;
            EndpointAddress address = new EndpointAddress("msmq.formatname:DIRECT=OS:" + Constants.QUEUE_PATH);

            ChannelFactory<ClassLib.IOrderProcessor> channelFactory = new ChannelFactory<ClassLib.IOrderProcessor>(binding, address);

            try
            {
                ClassLib.IOrderProcessor channel = channelFactory.CreateChannel();

                MyOrder order = new MyOrder();
                order.ID = DateTime.Now.Ticks.ToString();
                order.Name = "Order_" + order.ID;

                MsmqMessage<MyOrder> ordermsg = new MsmqMessage<MyOrder>(order);
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    channel.SubmitPurchaseOrderInMessage(ordermsg);
                    scope.Complete();
                }

                Console.WriteLine("Order has been submitted:{0}", ordermsg);
            }
            finally
            {
                channelFactory.Close();
            }
        }
开发者ID:yoshiao,项目名称:WCF_Samples,代码行数:30,代码来源:Program.cs

示例11: Execute

 public CommandResult Execute(Command command)
 {
     try
     {
         using (ChannelFactory<IIncinerateService> clientFactory = new ChannelFactory<IIncinerateService>())
         {
             NamedPipeTransportBindingElement transport = new NamedPipeTransportBindingElement();
             CustomBinding binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), transport);
             clientFactory.Endpoint.Binding = binding;
             clientFactory.Endpoint.Address = new EndpointAddress("net.pipe://IncinerateService/incinerate");
             IIncinerateService incinerateProxy = clientFactory.CreateChannel();
             CommandResult result = command.Execute(incinerateProxy);
             clientFactory.Close();
             return result;
         }
     }
     catch (FormatException ex)
     {
         Console.WriteLine("Illegal agruments");
     }
     catch (CommunicationObjectFaultedException ex)
     {
         throw new ServiceException("Service is not working", ex);
     }
     catch (EndpointNotFoundException ex)
     {
         throw new ServiceException("Service is not running", ex);
     }
     catch (CommunicationException ex)
     {
         throw new ServiceException("Can not connect to service", ex);
     }
     return null;
 }
开发者ID:Evlikat,项目名称:incinerate,代码行数:34,代码来源:IncinerateClient.cs

示例12: GetUsers

 public List<User> GetUsers(bool onlineOnly)
 {
     if (onlineOnly)
     {
         var cf = new ChannelFactory<IContactsStatusService>("contactsservice");
         var channel = cf.CreateChannel();
         var users = channel.GetOnlineContacts();
         if (cf.State == CommunicationState.Opened)
         {
             cf.Close();
         }
         return users;
     }
     else
     {
         var cf = new ChannelFactory<IDataService>("dataservice");
         var channel = cf.CreateChannel();
         var users = channel.GetUsers(appKey);
         if (cf.State == CommunicationState.Opened)
         {
             cf.Close();
         }
         return users;
     }
 }
开发者ID:Terfin,项目名称:SelaTalkBack,代码行数:25,代码来源:LoginOperations.cs

示例13: Main

        static void Main(string[] args)
        {
            ChannelFactory<ISampleContract> channelFactory = new ChannelFactory<ISampleContract>("sampleProxy");
            ISampleContract proxy = channelFactory.CreateChannel();

            int[] windSpeeds = new int[] { 100, 90, 80, 70, 60, 50, 40, 30, 20, 10 };

            Console.WriteLine("Reporting the next 10 wind speeds.");
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(windSpeeds[i] + " kph");
                try
                {
                    proxy.ReportWindSpeed(windSpeeds[i]);
                }
                catch (CommunicationException)
                {
                    Console.WriteLine("Server dropped a message.");
                }
            }

            Console.WriteLine("Press ENTER to shut down client");
            Console.ReadLine();

            ((IChannel)proxy).Close();
            channelFactory.Close();
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:27,代码来源:client.cs

示例14: Run

        public static void Run(int numberOfMessage)
        {
            try
            {
                int Iteration = numberOfMessage;

                string address = "net.msmq://localhost/private/ReceiveTx";
                NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None)
                {
                    ExactlyOnce = true,
                    Durable = true
                };

                ChannelFactory<IPurchaseOrderService> channelFactory = new ChannelFactory<IPurchaseOrderService>(binding, address);
                IPurchaseOrderService channel = channelFactory.CreateChannel();

                for (int i = 0; i < Iteration; i++)
                {
                    PurchaseOrder po = new PurchaseOrder()
                    {
                        PONumber = Guid.NewGuid().ToString(),
                        CustomerId = string.Format("CustomerId: {0}", i)
                    };

                    Console.WriteLine("Submitting an PO ...");
                    channel.SubmitPurchaseOrder(po);
                }

                channelFactory.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:35,代码来源:WorkflowTestClient.cs

示例15: test_account_manager_as_service

 public void test_account_manager_as_service()
 {
     ChannelFactory<IAccountService> channelFactory = new ChannelFactory<IAccountService>("");
     IAccountService proxy = channelFactory.CreateChannel();
     (proxy as ICommunicationObject).Open();
     channelFactory.Close();
 }
开发者ID:cohs88,项目名称:ps-building-end-to-end-multi-client-service-oriented-applicatins,代码行数:7,代码来源:ServiceAccessTests.cs


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