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


C# ChannelFactory.CreateChannel方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            EndpointAddress address = new EndpointAddress("http://127.0.0.1:3721/calculatorservice");
            using (ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>(new SimpleDatagramBinding(), address))
            {
                //创建第一个服务代理
                ICalculator proxy = channelFactory.CreateChannel();
                proxy.Add(1, 2);
                Console.WriteLine("Done");
                proxy.Add(1, 2);
                Console.WriteLine("Done");
                (proxy as ICommunicationObject).Close();

                //创建第二个服务代理
                proxy = channelFactory.CreateChannel();
                proxy.Add(1, 2);
                Console.WriteLine("Done");
                proxy.Add(1, 2);
                Console.WriteLine("Done");
                (proxy as ICommunicationObject).Close();

                channelFactory.Close();
            }
            Console.Read();
        }
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:25,代码来源:Program.cs

示例2: Test1

        private static void Test1()
        {
            try
            {
                Random rd = new Random();
                using (ChannelFactory<RoadLamps.Service.Old.IEquipmentService> channel = new ChannelFactory<RoadLamps.Service.Old.IEquipmentService>("CalculatorService"))
                {
                    for (int i = 0; i < 5; i++)
                    {
                        ThreadPool.QueueUserWorkItem(
                            delegate
                            {
                                RoadLamps.Service.Old.IEquipmentService ic = channel.CreateChannel();
                                using (ic as IDisposable)
                                {
                                    double x = 100 * rd.NextDouble();
                                    double y = 100 * rd.NextDouble();
                                    ic.Add(x, y);
                                    Console.WriteLine("第" + i.ToString() + "次请求已发送...");
                                }

                            });
                    }
                    RoadLamps.Service.Old.IEquipmentService ic2 = channel.CreateChannel();
                    ic2.CreateFile();
                    Console.WriteLine("请求发送完毕...");
                    Console.Read();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.Read();
            }
        }
开发者ID:kinpauln,项目名称:RoadLamps,代码行数:35,代码来源: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: InvokeThenTerminateSession

        public static void InvokeThenTerminateSession()
        {
            ChannelFactory<ICalculator> calculatorChannelFactory = new ChannelFactory<ICalculator>("httpEndpoint");
            Console.WriteLine("Create a calculator proxy: proxy1");
            ICalculator proxy1 = calculatorChannelFactory.CreateChannel();
            Console.WriteLine("Invocate  proxy1.Adds(1)");
            proxy1.Adds(1);
            Console.WriteLine("Invocate  proxy1.Adds(2)");
            proxy1.Adds(2);
            Console.WriteLine("The result return via proxy1.GetResult() is : {0}", proxy1.GetResult());
            Console.WriteLine("Invocate  proxy1.Adds(1)");
            try
            {
                proxy1.Adds(1);
            }
            catch (Exception ex)
            {
                Console.WriteLine("It is fail to invocate the Add after terminating session because \"{0}\"", ex.Message);
            }

            Console.WriteLine("Create a calculator proxy: proxy2");
            ICalculator proxy2= calculatorChannelFactory.CreateChannel();
            Console.WriteLine("Invocate  proxy2.Adds(1)");
            proxy2.Adds(1);
            Console.WriteLine("Invocate  proxy2.Adds(2)");
            proxy2.Adds(2);
            Console.WriteLine("The result return via proxy2.GetResult() is : {0}", proxy2.GetResult());

            Console.Read();
        }
开发者ID:rdzzg,项目名称:LearnningDemo,代码行数:30,代码来源:Program.cs

示例5: Main

 static void Main(string[] args)
 {
     using (ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>("calculatorservice"))
     {
         ICalculator serviceProxy1 = channelFactory.CreateChannel();
         serviceProxy1.Add(1, 2);
         ICalculator serviceProxy2 = channelFactory.CreateChannel();
         serviceProxy2.Add(1, 2);
     }
     Console.Read();
 }
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:11,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            Console.WriteLine(
                "Press <enter> to open a channel and send a request.");

            Console.ReadLine();
            
            MessageHeader shareableInstanceContextHeader = MessageHeader.CreateHeader(
                    CustomHeader.HeaderName,
                    CustomHeader.HeaderNamespace,
                    Guid.NewGuid().ToString());

            ChannelFactory<IEchoService> channelFactory =
                new ChannelFactory<IEchoService>("echoservice");
            
            IEchoService proxy = channelFactory.CreateChannel();


            using (new OperationContextScope((IClientChannel)proxy))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(shareableInstanceContextHeader);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Service returned: " + proxy.Echo("Apple"));
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            ((IChannel)proxy).Close();

            Console.WriteLine("Channel No 1 closed.");

            Console.WriteLine(
                "Press <ENTER> to send another request from a different channel " + 
                "to the same instance. ");            

            Console.ReadLine();

            proxy = channelFactory.CreateChannel();

            using (new OperationContextScope((IClientChannel)proxy))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(shareableInstanceContextHeader);
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Service returned: " + proxy.Echo("Apple"));
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            
            ((IChannel)proxy).Close();

            Console.WriteLine("Channel No 2 closed.");
		
            Console.WriteLine("Press <ENTER> to complete test.");
            Console.ReadLine();
        }
开发者ID:ssickles,项目名称:archive,代码行数:53,代码来源:Client.cs

示例7: Main

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


            Uri address = new Uri("net.tcp://localhost:4000/IDatabaseManager");
            NetTcpBinding binding = new NetTcpBinding();

            ChannelFactory<IDatabaseManager> factory = new ChannelFactory<IDatabaseManager>(binding, new EndpointAddress(address));

            IDatabaseManager proxy = factory.CreateChannel();

            Console.WriteLine("Database Manager started");
            Digitalinput i = new Digitalinput();

            i.AutoOrManual = true;
            i.Descrition = "Pumpa";
            i.Driver = new SimulationDriver();
            i.TagName = "di1";

            Console.WriteLine("Adding DI tag");
            proxy.addDI(i);

            proxy.removeElement("bb");
            Console.WriteLine("Turn on scan");
            proxy.turnOnScan("di1");


            Console.ReadLine();
        }
开发者ID:masterorg,项目名称:SvadaSystem,代码行数:30,代码来源:Program.cs

示例8: Connect

        public void Connect(string endPointAddress)
        {
            if (this._lucidServer != null)
            {
                Disconnect();
            }

            EndpointAddress serverEndpointAddress;
            try
            {
                serverEndpointAddress = new EndpointAddress(endPointAddress);
            }
            catch
            {
                // bad url
                throw new Exception("Bad server URL: " + endPointAddress);
            }
            Binding binding = new NetTcpBinding(SecurityMode.None, true);
            binding.ReceiveTimeout = TimeSpan.FromSeconds(10);
            binding.SendTimeout = TimeSpan.FromSeconds(10);
            binding.OpenTimeout = TimeSpan.FromSeconds(10);
            var factory = new ChannelFactory<ILucidService>(binding, serverEndpointAddress);

            this._lucidServer = factory.CreateChannel();
            // let server know we are available
            this._lucidServer.RegisterClient();

            Inv.Log.Log.WriteMessage("Connected to server " + endPointAddress);
        }
开发者ID:mkonicek,项目名称:raytracer,代码行数:29,代码来源:LucidClient.cs

示例9: DoCreate

		IFS2Contract DoCreate(string serverAddress)
		{
			if (serverAddress.StartsWith("net.pipe:"))
			{
				if (!FS2LoadHelper.Load())
					BalloonHelper.ShowFromFiresec("Не удается соединиться с агентом 2");
			}

			var binding = BindingHelper.CreateBindingFromAddress(serverAddress);

			var endpointAddress = new EndpointAddress(new Uri(serverAddress));
			ChannelFactory = new ChannelFactory<IFS2Contract>(binding, endpointAddress);

			foreach (OperationDescription operationDescription in ChannelFactory.Endpoint.Contract.Operations)
			{
				DataContractSerializerOperationBehavior dataContractSerializerOperationBehavior = operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
				if (dataContractSerializerOperationBehavior != null)
					dataContractSerializerOperationBehavior.MaxItemsInObjectGraph = Int32.MaxValue;
			}

			ChannelFactory.Open();

			IFS2Contract firesecService = ChannelFactory.CreateChannel();
			(firesecService as IContextChannel).OperationTimeout = TimeSpan.FromMinutes(10);
			return firesecService;
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:26,代码来源:FS2Factory.cs

示例10: ServerAncClientExceptionsEndpointBehavior

        public void ServerAncClientExceptionsEndpointBehavior()
        {
            var hook = new ExceptionsEndpointBehaviour();
            var address = @"net.pipe://127.0.0.1/test" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var serv = new ExceptionService();
            using (var host = new ServiceHost(serv, new Uri[] { new Uri(address), }))
            {
                var b = new NetNamedPipeBinding();
                var serverEndpoint = host.AddServiceEndpoint(typeof(IExceptionService), b, address);
                serverEndpoint.Behaviors.Add(hook);

                host.Open();

                var f = new ChannelFactory<IExceptionService>(b);
                f.Endpoint.Behaviors.Add(hook);

                var c = f.CreateChannel(new EndpointAddress(address));

                try
                {
                    c.DoException("message");
                }
                catch (InvalidOperationException ex)
                {
                    StringAssert.AreEqualIgnoringCase("message", ex.Message);
                }
                host.Abort();
            }
        }
开发者ID:OpenSharp,项目名称:NDceRpc,代码行数:29,代码来源:ServiceEndpointBehavioursTests.cs

示例11: WCFClient

        public WCFClient(IEventAggregator eventBus) {
            _eventBus = eventBus;
            _pipeFactory = new ChannelFactory<IUpdaterWCF>(new NetNamedPipeBinding(), new EndpointAddress(
                "net.pipe://localhost/UpdaterWCF_Pipe"));

            _pipeProxy = _pipeFactory.CreateChannel();
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:7,代码来源:WCFClient.cs

示例12: ChannelFactoryExample

        static void ChannelFactoryExample(string baseUri)
        {
            var factory = new ChannelFactory<ISimpleService>(
                new JsonRpcHttpBinding(),
                new EndpointAddress(baseUri + "/json-rpc"));

            factory.Endpoint.Behaviors.Add(new JsonRpcBehavior());

            var client = factory.CreateChannel();

            Console.WriteLine("SimpleMethod(\"World\"): " + client.SimpleMethod("World"));
            Console.WriteLine("Add(42, 24): " + client.Add(42, 24).ToString());
            Console.WriteLine("GetComplexType(3.14): " + client.GetComplexType(3.14).ToString());

            Console.Write("Call VoidMethod()... ");
            client.VoidMethod();
            Console.WriteLine("success");

            Console.WriteLine("ComplexArg(arg): " +
                client.ComplexArg(new ComplexType { Name = "1234", BirthDate = DateTime.Now }));

            try {
                var result = client.GotException();
            } catch (JsonRpcException e) {
                Console.WriteLine("GotException(): " + e.ToString());
            }
        }
开发者ID:kmvi,项目名称:JsonRpc.ServiceModel,代码行数:27,代码来源:Program.cs

示例13: CoreServiceProvider

        public CoreServiceProvider()
        {
            var binding = new BasicHttpBinding
            {
                MaxReceivedMessageSize = 10485760,
                ReaderQuotas = new XmlDictionaryReaderQuotas
                {
                    MaxStringContentLength = 10485760,
                    MaxArrayLength = 10485760
                },
                Security = new BasicHttpSecurity
                {
                    Mode = BasicHttpSecurityMode.TransportCredentialOnly,
                    Transport = new HttpTransportSecurity
                    {
                        ClientCredentialType = HttpClientCredentialType.Windows
                    }
                }
            };

            string coreServiceUrl = ConfigurationManager.AppSettings[Constants.TRIDION_CME_URL] + "/webservices/CoreService2013.svc/basicHttp";
            Console.WriteLine("Connect to CoreService " + coreServiceUrl);

            EndpointAddress endpoint = new EndpointAddress(coreServiceUrl);
            factory = new ChannelFactory<ICoreService>(binding, endpoint);

            string userName = ConfigurationManager.AppSettings[Constants.USER_NAME];
            string password = ConfigurationManager.AppSettings[Constants.PASSWORD];
            factory.Credentials.Windows.ClientCredential = new NetworkCredential(userName, password);

            Client = factory.CreateChannel();

            UserData user = Client.GetCurrentUser();
            Console.WriteLine("Connected as {0} ({1})", user.Description, user.Title);
        }
开发者ID:mitza13,项目名称:yet-another-tridion-blog,代码行数:35,代码来源:CoreServiceClient.cs

示例14: Test

        static void Test()
        {
            try
            {
                NetTcpBinding binding = new NetTcpBinding();
                binding.TransferMode = TransferMode.Streamed;
                binding.SendTimeout = new TimeSpan(0, 0, 2);

                channelFactory = new ChannelFactory<IFileUpload>(binding, ClientConfig.WCFAddress);

                _proxy = channelFactory.CreateChannel();

                (_proxy as ICommunicationObject).Open();

                Console.WriteLine("主方法开始执行:" + DateTime.Now.ToString());
                _proxy.BeginAdd(1, 2, EndAdd, null);
                Console.WriteLine("主方法结束:" + DateTime.Now.ToString());

            }
            catch (Exception ex)
            {
                Tools.LogWrite(ex.ToString());
                Console.WriteLine(ex.ToString());
            }
        }
开发者ID:ufo20020427,项目名称:FileUpload,代码行数:25,代码来源:Program.cs

示例15: TestMethod1

        public void TestMethod1()
        {
            var token = GetToken();

            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            var binding = new WebHttpBinding
            {
                Security =
                {
                    Mode = WebHttpSecurityMode.Transport,
                    Transport = {ClientCredentialType = HttpClientCredentialType.None}
                }
            };

            using (var factory = new ChannelFactory<IThingsService>(binding, "https://localhost:1234/things"))
            {
                factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
                var channel = factory.CreateChannel();

                using (new OperationContextScope((IContextChannel)channel))
                {
                    WebOperationContext.Current.OutgoingRequest.Headers.Add("token", token);
                    var nodes = channel.GetNodes();
                }
            }
        }
开发者ID:tacerra,项目名称:HomeAutomationServer,代码行数:27,代码来源:UnitTest1.cs


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