• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ServiceModel.ChannelFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ChannelFactory类属于System.ServiceModel命名空间,在下文中一共展示了ChannelFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Submit

        public void Submit(Order order)
        {
            Console.WriteLine("Begin to process the order of the order No.: {0}", order.OrderNo);
            FaultException exception = null;
            if (order.OrderDate < DateTime.Now) {
                exception = new FaultException(new FaultReason("The order has expried"), new FaultCode("sender"));
                Console.WriteLine("It's fail to process the order.\n\tOrder No.: {0}\n\tReason:{1}", order.OrderNo, "The order has expried");
            } else {
                Console.WriteLine("It's successful to process the order.\n\tOrder No.: {0}", order.OrderNo);
            }
            NetMsmqBinding binding = new NetMsmqBinding();
            binding.ExactlyOnce = false;
            binding.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
            binding.Security.Transport.MsmqProtectionLevel = ProtectionLevel.None;

            ChannelFactory<IOrderRessponse> channelFactory = new ChannelFactory<IOrderRessponse>(binding);
            OrderResponseContext responseContext = OrderResponseContext.Current;

            IOrderRessponse channel = channelFactory.CreateChannel(new EndpointAddress(responseContext.ResponseAddress));

            using (OperationContextScope contextScope = new OperationContextScope(channel as IContextChannel)) {
                channel.SubmitOrderResponse(order.OrderNo, exception);
            }
            Console.Read();
        }
开发者ID:0811112150,项目名称:HappyDayHistory,代码行数:25,代码来源:OrderProcessorService.cs


示例2: 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


示例3: RegisterAsServer

 public static ITestRunner RegisterAsServer(ITestOutput output, Options options)
 {
     var host = new ServiceHost(output);
     int i;
     for (i = 0; i < 50; i += 10) {
         try {
             host.AddServiceEndpoint(typeof(ITestOutput), BindingFactory(), "http://localhost:" + (StartPort + i) + "/");
             break;
         } catch (AddressAlreadyInUseException) {
         }
     }
     host.Open();
     var start = DateTime.Now;
     Exception final = null;
     var res = new ChannelFactory<ITestRunner>(BindingFactory(), "http://localhost:" + (StartPort + i + 1) + "/").CreateChannel();
     while (DateTime.Now - start < TimeSpan.FromSeconds(5)) {
         try {
             res.Ping();
             return res;
         } catch (Exception e) {
             final = e;
         }
     }
     throw final;
 }
开发者ID:SimonRichards,项目名称:msUnit,代码行数:25,代码来源:ConnectionFactory.cs


示例4: GetRepositoryInformation

        public IEnumerable<RepositoryInformation> GetRepositoryInformation(string queryString)
        {
            if(_repositoryNames != null)
                return _repositoryNames; //for now, there's no way to get an updated list except by making a new client

            const string genericUrl = "scheme://path?";
            var finalUrl = string.IsNullOrEmpty(queryString)
                               ? queryString
                               : genericUrl + queryString;
            var binding = new NetTcpBinding
            {
                Security = {Mode = SecurityMode.None}
            };

            var factory = new ChannelFactory<IChorusHubService>(binding, _chorusHubServerInfo.ServiceUri);

            var channel = factory.CreateChannel();
            try
            {
                var jsonStrings = channel.GetRepositoryInformation(finalUrl);
                _repositoryNames = ImitationHubJSONService.ParseJsonStringsToChorusHubRepoInfos(jsonStrings);
            }
            finally
            {
                var comChannel = (ICommunicationObject)channel;
                if (comChannel.State != CommunicationState.Faulted)
                {
                    comChannel.Close();
                }
            }
            return _repositoryNames;
        }
开发者ID:JessieGriffin,项目名称:chorus,代码行数:32,代码来源:ChorusHubClient.cs


示例5: Main

        static void Main(string[] args)
        {
            Console.Title = "CLIENT";

            // Указание, где ожидать входящие сообщения.
            Uri address = new Uri("http://localhost:4000/IContract");

            // Указание, как обмениваться сообщениями.
            BasicHttpBinding binding = new BasicHttpBinding();

            // Создание Конечной Точки. 
            EndpointAddress endpoint = new EndpointAddress(address);

            // Создание фабрики каналов.
            ChannelFactory<IContract> factory = new ChannelFactory<IContract>(binding, endpoint);

            // Использование factory для создания канала (прокси).
            IContract channel = factory.CreateChannel();
            
            // Использование канала для отправки сообщения получателю и приема ответа.
            string response = channel.Say("Hello WCF!");

            Console.WriteLine(response);

            // Задержка.
            Console.ReadKey();
        }
开发者ID:novakvova,项目名称:WCFLesson1,代码行数:27,代码来源:Client.cs


示例6: Abort

 private static void Abort(IChannel channel, ChannelFactory channelFactory)
 {
     if (channel != null)
         channel.Abort();
     if (channelFactory != null)
         channelFactory.Abort();
 }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:7,代码来源:client.cs


示例7: Send

        public static void Send(Pager model)
        {
            if (model.To == null || string.IsNullOrWhiteSpace(model.Message)) return;

            using (model.Modifier(x => x.Message))
            {

                Message message = new Message
                {
                    CreatedTime   = DateTime.Now,
                    From          = From,
                    To            = model.To,
                    ContentAsText = model.Message
                };

                model.Message = string.Empty;
                model.History.Add(message)  ;

                m_history.Add(message);

                using (var factory = new ChannelFactory<IMessageHost>(new BasicHttpBinding(), message.To.Uri))
                {
                     factory.Open();
             					 factory.CreateChannel().Send(new Request<Message>(message));
                }

            }
        }
开发者ID:vadimdementey,项目名称:WpfPager,代码行数:28,代码来源:PagerController.cs


示例8: Client

        public Client(string serverAddress)
        {
            if (EventManager.Instance.Protocol == EventManager.XML_RPC)
            {
                address = serverAddress;
                Uri eventManagerAddress;
                if (EventManager.singleMachineDebug)
                    //For test on a single machine
                    eventManagerAddress = new Uri("http://" + serverAddress + "/EventManager");
                else
                    eventManagerAddress = new Uri("http://" + serverAddress + ":8000/xmlrpc/EventManager");

                ChannelFactory<IEMServiceWCF_XML_RPC> eventManagerFactory =
                    new ChannelFactory<IEMServiceWCF_XML_RPC>(
                        new WebHttpBinding(WebHttpSecurityMode.None),
                        new EndpointAddress(eventManagerAddress));
                eventManagerFactory.Endpoint.EndpointBehaviors.Add(new Microsoft.Samples.XmlRpc.XmlRpcEndpointBehavior());

                eManagerWCF_XML_RPC = eventManagerFactory.CreateChannel();
            }
            else if (EventManager.Instance.Protocol == EventManager.REMOTING)
            {
                eManagerREMOTING = (EMServiceRemoting)Activator.GetObject(typeof(EMServiceRemoting), "http://" + serverAddress + ":8080/EventManager/RemotingService");
            }
        }
开发者ID:yonglehou,项目名称:EventManager_CSharp_WCF,代码行数:25,代码来源:Client.cs


示例9: MainPageLoaded

        void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            // Simple Version
            var basicHttpBinding = new BasicHttpBinding();
            var endpointAddress = new EndpointAddress("http://localhost:50738/UserGroupEvent.svc");
            var userGroupEventService = new ChannelFactory<IAsyncUserGroupEventService>(basicHttpBinding, endpointAddress).CreateChannel();

            AsyncCallback asyncCallBack = delegate(IAsyncResult result)
            {
                var response = ((IAsyncUserGroupEventService)result.AsyncState).EndGetUserGroupEvent(result);
                Dispatcher.BeginInvoke(() => SetUserGroupEventData(response));
            };
            userGroupEventService.BeginGetUserGroupEvent("123", asyncCallBack, userGroupEventService);

            // Deluxe Variante mit eigenem Proxy
            var channel = new UserGroupEventServiceProxy("BasicHttpBinding_IAsyncUserGroupEventService").Channel;
            channel.BeginGetUserGroupEvent("123", ProcessResult, channel);

            // Variante mit Faulthandler
            using (var scope = new OperationContextScope((IContextChannel)channel))
            {
                var messageHeadersElement = OperationContext.Current.OutgoingMessageHeaders;
                messageHeadersElement.Add(MessageHeader.CreateHeader("DoesNotHandleFault", "", true));
                channel.BeginGetUserGroupEventWithFault("123", ProcessResultWithFault, channel);
            }
        }
开发者ID:sven-s,项目名称:SilverlightErfahrungsbericht,代码行数:26,代码来源:MainPage.xaml.cs


示例10: Main

        static void Main(string[] args)
        {
            try
            {
                using (var cf = new ChannelFactory<IRestService>(new WebHttpBinding(), RestUri))
                {
                    cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
                    var channel = cf.CreateChannel();

                    Console.WriteLine("Calling Multiply: ");
                    var result = channel.Multiply(6, 23);
                    Console.WriteLine("6*23 = {0}", result);

                    Console.WriteLine("");

                    Console.WriteLine("Calling CreateNewUser (POST): ");
                    var result1 = channel.CreateNewUser("foobar", "verystrongpasswortnot");
                    Console.WriteLine("User created? {0}", result1);
                    Console.WriteLine("");
                }

                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("An exception occurred: {0}", e.Message);
            }
        }
开发者ID:CodingJournal,项目名称:WcfWebApiRestExample,代码行数:29,代码来源:Program.cs


示例11: Main

        static void Main(string[] args)
        {
            Console.Title = "CLIENT";

            // Указание, где ожидать входящие сообщения.
            Uri address = new Uri("http://localhost:4000/IContract");  // ADDRESS.   (A)

            // Указание, как обмениваться сообщениями.
            BasicHttpBinding binding = new BasicHttpBinding();         // BINDING.   (B)

            // Создание Конечной Точки.
            EndpointAddress endpoint = new EndpointAddress(address);

            // Создание фабрики каналов.
            ChannelFactory<IContract> factory = new ChannelFactory<IContract>(binding, endpoint);  // CONTRACT.  (C) 

            // Использование factory для создания канала (прокси).
            IContract channel = factory.CreateChannel();
            
            // Использование канала для отправки сообщения получателю.
            channel.Say("Hello WCF!");// сложный механизм

            // Задержка.
            Console.ReadKey();
        }
开发者ID:novakvova,项目名称:WCFLesson1,代码行数:25,代码来源:Client.cs


示例12: GetCustomersOrders

        public IEnumerable<Order> GetCustomersOrders(CrmService.Contracts.Customer customer)
        {
            var channelFactory = new ChannelFactory<CrmService.Contracts.ICrmService>("CrmEP");

            CrmService.Contracts.ICrmService proxy = channelFactory.CreateChannel();
            return proxy.GetCustomerOrders(customer.ID, null, null);
        }
开发者ID:jonteho,项目名称:ticketing-office,代码行数:7,代码来源:Orders.cs


示例13: ImitatorServiceFactory

		public ImitatorServiceFactory()
		{
			var binding = BindingHelper.CreateBindingFromAddress("net.pipe://127.0.0.1/GKImitator/");
			var endpointAddress = new EndpointAddress(new Uri("net.pipe://127.0.0.1/GKImitator/"));
			_channelFactory = new ChannelFactory<IImitatorService>(binding, endpointAddress);
			_channelFactory.Open();
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:7,代码来源:ImitatorServiceFactory.cs


示例14: 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


示例15: 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


示例16: 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


示例17: 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


示例18: 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


示例19: 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


示例20: StartDownload

        private void StartDownload()
        {
            new Thread(delegate()
            {
                bool retry = false;
                int count = 0;

                do {
                    retry = false;
                    try {
                        NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                        EndpointAddress address = new EndpointAddress("net.pipe://localhost/download");
                        using (ChannelFactory<IDownloadManager> factory = new ChannelFactory<IDownloadManager>(binding, address))
                        {
                            IDownloadManager dm = factory.CreateChannel();

                            if (dm != null)
                            {
                                string msg = dm.CopyFile("test file");
                                MessageBox.Show(msg);
                            }

                            factory.Close();
                        }
                    }
                    catch (CommunicationException)
                    {
                        retry = (count++ < 30);
                        Thread.Sleep(1000);
                    }
                } while(retry);

            }).Start();
        }
开发者ID:kirigishi123,项目名称:try_samples,代码行数:34,代码来源:Form1.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ServiceModel.EndpointAddress类代码示例发布时间:2022-05-26
下一篇:
C# ServiceModel.BasicHttpBinding类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap