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


C# DuplexChannelFactory.CreateChannel方法代码示例

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


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

示例1: connect

        public void connect(String url, IAudioServiceCallBack callback, EventHandler openedEvt = null, EventHandler faultEvt = null) //url = "net.tcp://localhost:8080/AudioService"
        {
            try
            {
                 duplex = new DuplexChannelFactory<IAudioService>(callback, new NetTcpBinding(),
                     new EndpointAddress(url));
                
                 service = duplex.CreateChannel();
                 channel = (ICommunicationObject)service;
                 IClientChannel c = (IClientChannel)channel;
                 c.OperationTimeout = TimeSpan.FromSeconds(5);
                 
                 channel.Opened += new EventHandler(delegate(object o, EventArgs e)
                    {
                        Console.WriteLine("Connection ok!");
                    });

                if(openedEvt != null)
                 channel.Opened += openedEvt;
                if(faultEvt != null)
                 channel.Faulted += faultEvt;
                 channel.Faulted += new EventHandler(delegate(object o, EventArgs e)
                    {
                        Console.WriteLine("Connection lost");
                    });

            }
            catch (Exception e)
            {
                Console.WriteLine("Connection error: " + e.Message);
            }
        }
开发者ID:kaizadj,项目名称:ebu-radio-production,代码行数:32,代码来源:AudioServiceConnection.cs

示例2: OrationiSlave

		public OrationiSlave()
		{
			Binding binding = new NetTcpBinding(SecurityMode.None);
			EndpointAddress defaultEndpointAddress = new EndpointAddress("net.tcp://localhost:57344/Orationi/Master/v1/");
			EndpointAddress discoveredEndpointAddress = DiscoverMaster();
			ContractDescription contractDescription = ContractDescription.GetContract(typeof(IOrationiMasterService));
			ServiceEndpoint serviceEndpoint = new ServiceEndpoint(contractDescription, binding, discoveredEndpointAddress ?? defaultEndpointAddress);
			var channelFactory = new DuplexChannelFactory<IOrationiMasterService>(this, serviceEndpoint);

			try
			{
				channelFactory.Open();
			}
			catch (Exception ex)
			{
				channelFactory?.Abort();
			}

			try
			{
				_masterService = channelFactory.CreateChannel();
				_communicationObject = (ICommunicationObject)_masterService;
				_communicationObject.Open();
			}
			catch (Exception ex)
			{
				if (_communicationObject != null && _communicationObject.State == CommunicationState.Faulted)
					_communicationObject.Abort();
			}
		}
开发者ID:Rankcore,项目名称:Orationi,代码行数:30,代码来源:OrationiSlave.cs

示例3: submitButton_Click

        private void submitButton_Click(object sender, RoutedEventArgs e)
        {
            var login = loginTextBox.Text;
            var pass = passwordTextBox.Password;

            Action<String> status = s => {
                statusLabel.Content = s;
                statusLabel.ToolTip = s;
            };

            try {
                channelFactory = new DuplexChannelFactory<IService>(new ClientImplementation(_MainWindow), "DnDServiceEndPoint");
                server = channelFactory.CreateChannel();

                if (server.Login(login, pass)) {
                    _MainWindow.InitializeServer(channelFactory, server);
                    this.DialogResult = true;
                } else {
                    statusLabel.Content = "Login lub hasło nie są poprawne!";
                    return;
                }

            } catch (Exception ex) {
                statusLabel.Content = "Nastąpił błąd! Spróbuj ponownie";
                System.IO.StreamWriter file = new System.IO.StreamWriter("log.txt");
                file.WriteLine(ex.ToString());
                file.Close();
                return;
            }
            this.Close();
        }
开发者ID:kacpak,项目名称:Dungeons_and_Dragons,代码行数:31,代码来源:ClientLogin.xaml.cs

示例4: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            EndpointAddress endpointAddress = new EndpointAddress("http://localhost:31337/BesiegedServer/BesiegedMessage");
            DuplexChannelFactory<IBesiegedServer> duplexChannelFactory = new DuplexChannelFactory<IBesiegedServer>(m_Client, new WSDualHttpBinding(), endpointAddress);
            m_BesiegedServer = duplexChannelFactory.CreateChannel();

            // Subscribe in a separate thread to preserve the UI thread
            Task.Factory.StartNew(() =>
            {
                CommandConnect commandConnect = new CommandConnect();
                m_BesiegedServer.SendMessage(commandConnect.ToXml());
            });

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    Command command = m_Client.MessageQueue.Take();
                    ProcessMessage(command);
                }
            }, TaskCreationOptions.LongRunning);

            GameLobbyCollection = new ObservableCollection<CommandNotifyGame>();
            DataContext = this;
        }
开发者ID:WonderPanda,项目名称:Besieged,代码行数:27,代码来源:MainWindow.xaml.cs

示例5: RegisterViewModel

 public RegisterViewModel()
 {
     var channelFactory = new DuplexChannelFactory<IChattingService>(new ClientService(), "ChattingServiceEndPoint");
     _server = channelFactory.CreateChannel();
     Register = new RelayCommand(OnRegister, () => !(string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password)));
     ClearCommand = new RelayCommand(OnClear);
 }
开发者ID:DavidNemeth,项目名称:DesktopApps,代码行数:7,代码来源:RegisterViewModel.cs

示例6: ConnectIpc

        public static void ConnectIpc(IServiceRemotingCallback serviceRemotingCallback)
        {
            InstanceContext instanceContext = new InstanceContext(serviceRemotingCallback);

            PipeFactory = new DuplexChannelFactory<IServiceRemoting>(instanceContext, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/BitCollectors.PlinkService/PlinkService"));
            RemotingObject = PipeFactory.CreateChannel();
        }
开发者ID:tk-s,项目名称:BitCollectors.PlinkService,代码行数:7,代码来源:WcfClientHelper.cs

示例7: MonitorForm_Load

        //其他成员
        private void MonitorForm_Load(object sender, EventArgs e)
        {
            string header = string.Format("{0, -13}{1, -22}{2}", "Client", "Time", "Event");
            this.listBoxExecutionProgress.Items.Add(header);
            _syncContext = SynchronizationContext.Current;
            _callbackInstance = new InstanceContext(new CalculatorCallbackService());
            _channelFactory = new DuplexChannelFactory<ICalculator>(_callbackInstance, "calculatorservice");

            EventMonitor.MonitoringNotificationSended += ReceiveMonitoringNotification;
            this.Disposed += delegate
            {
            EventMonitor.MonitoringNotificationSended -= ReceiveMonitoringNotification;
            _channelFactory.Close();
            };

            for (int i = 0; i < 2; i++)
            {
            ThreadPool.QueueUserWorkItem(state =>
            {
                int clientId = Interlocked.Increment(ref _clientId);
                EventMonitor.Send(clientId, EventType.StartCall);
                ICalculator proxy = _channelFactory.CreateChannel();
                using (OperationContextScope contextScope = new OperationContextScope(proxy as IContextChannel))
                {
                    MessageHeader<int> messageHeader = new MessageHeader<int>(clientId);
                    OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader.GetUntypedHeader(EventMonitor.CientIdHeaderLocalName, EventMonitor.CientIdHeaderNamespace));
                    proxy.Add(1, 2);
                }
                EventMonitor.Send(clientId, EventType.EndCall);
            }, null);
            }
        }
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:33,代码来源:MonitorForm.cs

示例8: Main

        static void Main(string[] args)
        {
            var fact = new ChannelFactory<IDeviceManagerService>("deviceEndpoint");

            InstanceContext callback = new InstanceContext(new ServiceCallback());

            var dup = new DuplexChannelFactory<ICardReaderEventsSubscribe>(callback, "dupSocket");

            var cardReaderSub = dup.CreateChannel();

            var cha = fact.CreateChannel();

            using (fact)
            {
                var devices = cha.GetAllDevices();
                //cha.Open(new  devices[0].FullSerialNumber );

            }
            Console.WriteLine("try a new");
            Console.ReadKey();

            Console.WriteLine("REading duplex");

            cardReaderSub.SubscribeToCardSwipeByhost("Local");

            Console.ReadKey();

            var fact1 = new ChannelFactory<IDeviceManagerService>("deviceEndpoint");
            var cha1 = fact1.CreateChannel();

            using (fact1)
            {
                var devices = cha1.GetAllDevices();
            }
        }
开发者ID:goodwillguy,项目名称:DeviceManagerService,代码行数:35,代码来源:Program.cs

示例9: Connect

        /// <summary>
        /// Connect to game server
        /// </summary>
        /// <param name="IP"></param>
        /// <returns></returns>
        public bool Connect(String IP)
        {

            // Create a pipeFactory
            DuplexChannelFactory<IMessage> pipeFactory =
                  new DuplexChannelFactory<IMessage>(
                      new InstanceContext(this),
                      new NetTcpBinding(),
                //new EndpointAddress(String.Format("net.tcp://{0}:8000/GameServer", IP)));
                      new EndpointAddress(String.Format("net.tcp://{0}:8000/GameServer", "localhost")));
            try
            {

                // Creating the communication channel
                pipeProxy = pipeFactory.CreateChannel();
                // register for events 
                pipeProxy.Subscribe();
                // join the game 
                myID = pipeProxy.join(me.Username, me.money, me.numOfGames, me.ID);
                if (pipeProxy.runningGame())
                {
                    pipeProxy.resetGame();
                }
                return true;
            }
            catch (Exception e)
            {
                
                return false;
            }
        }
开发者ID:srgrn,项目名称:BlackJack.Net,代码行数:36,代码来源:GameScreen.cs

示例10: StartP2PClient

        private  void StartP2PClient( )
        {
            string s = ConfigurationManager.AppSettings["IsSupportGroup"];
            if (s.Equals("no", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            InstanceContext context = new InstanceContext(new P2PChatService());
            DuplexChannelFactory<IP2PChatService> factory = new DuplexChannelFactory<IP2PChatService>(context,"p2p", new EndpointAddress("net.p2p://" + groupId));


            channel = factory.CreateChannel();
            clients.Add(groupId, this);
           

           
            new Thread(new ThreadStart(() =>
            {
                try
                {
                    channel.Join();
                }
                catch (Exception ex)
                {
                    MyLogger.Logger.Error("进入群组聊天室时出错",ex);
                }
            })).Start();
           
        }
开发者ID:ITPuppy,项目名称:myRepo,代码行数:29,代码来源:P2PClient.cs

示例11: MainWindow

        public MainWindow()
        {
            try
            {
                //Center the window on startup
                WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                InitializeComponent();
                createGrid();
                // Configure the Endpoint details
                DuplexChannelFactory<ITileBag> channel = new DuplexChannelFactory<ITileBag>(this, "TileBag");

                // Activate a remote Bag object
                bag = channel.CreateChannel();
                // Register this client for the callback service
                bag.RegisterForCallbacks();

                lblPlayerScore.Content = 0;
                pWin = new PlayerLobby(this, bag.ClientCount);
                pWin.Show();
                this.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Initializing Window " + ex.Message);
            }
        }
开发者ID:Jardjard,项目名称:Scrabblesque,代码行数:26,代码来源:MainWindow.xaml.cs

示例12: ClientViewModel

 public ClientViewModel()
 {
     var channelFactory = new DuplexChannelFactory<IChattingService>(new ClientService(), "ChattingServiceEndPoint");
     _server = channelFactory.CreateChannel();
     This = this;
     CreateCommands();
 }
开发者ID:DavidNemeth,项目名称:DesktopApps,代码行数:7,代码来源:ClientViewModel.cs

示例13: TestOneWayCallbackConcurencyOnNamedPipe

        public void TestOneWayCallbackConcurencyOnNamedPipe()
        {
            var address = @"net.pipe://127.0.0.1/testpipename" + MethodBase.GetCurrentMethod().Name;
            var srv = new CallbackService();
            var callback = new CallbackServiceCallback();
            using (var server = new ServiceHost(srv, new Uri(address)))
            {
                server.AddServiceEndpoint(typeof(ICallbackService), new NetNamedPipeBinding { }, address);
                server.Open();

                using (var channelFactory = new DuplexChannelFactory<ICallbackService>(new InstanceContext(callback), new NetNamedPipeBinding { }))
                {

                    var client = channelFactory.CreateChannel(new EndpointAddress(address));

                    for (int i = 0; i < 20; i++)
                        client.OneWayExecute();
                    while (callback.Count != 20)
                    {
                        Thread.Sleep(10);
                    }

                }
            }
        }
开发者ID:OpenSharp,项目名称:NDceRpc,代码行数:25,代码来源:ConcurrencyTests.cs

示例14: RobotClient

 public RobotClient()
 {
     // Initilize communication channel
     DuplexChannelFactory = new DuplexChannelFactory<IUiPathRemoteDuplexContract>(new InstanceContext(this), "DefaultDuplexEndpoint");
     DuplexChannelFactory.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
     Channel = DuplexChannelFactory.CreateChannel();
 }
开发者ID:UiPath,项目名称:SDK,代码行数:7,代码来源:RobotClient.cs

示例15: NetTcpBinding_DuplexCallback_ReturnsXmlComplexType

    public static void NetTcpBinding_DuplexCallback_ReturnsXmlComplexType()
    {
        DuplexChannelFactory<IWcfDuplexService_Xml> factory = null;
        NetTcpBinding binding = null;
        WcfDuplexServiceCallback callbackService = null;
        InstanceContext context = null;
        IWcfDuplexService_Xml serviceProxy = null;
        Guid guid = Guid.NewGuid();

        try
        {
            binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;

            callbackService = new WcfDuplexServiceCallback();
            context = new InstanceContext(callbackService);

            factory = new DuplexChannelFactory<IWcfDuplexService_Xml>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_XmlDuplexCallback_Address));
            serviceProxy = factory.CreateChannel();

            serviceProxy.Ping_Xml(guid);
            XmlCompositeTypeDuplexCallbackOnly returnedType = callbackService.XmlCallbackGuid;

            // validate response
            Assert.True((guid.ToString() == returnedType.StringValue), String.Format("The Guid to string value sent was not the same as what was returned.\nSent: {0}\nReturned: {1}", guid.ToString(), returnedType.StringValue));

            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:34,代码来源:DataContractTests.4.1.0.cs


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