當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。