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


C# ServiceModel.ChannelFactory类代码示例

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


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


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