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


C# ServiceModel.NetTcpBinding类代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {

            NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport);
            string address = "net.tcp://localhost:9999/WCFService";
            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;

            ServiceHost host = new ServiceHost(typeof(Service));
            host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.ChainTrust;
            host.Credentials.ClientCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
            host.AddServiceEndpoint(typeof(IContract), binding, address);
            host.Credentials.ServiceCertificate.SetCertificate("CN=srv", StoreLocation.LocalMachine, StoreName.My);
            host.Open();

            NetTcpBinding bindingForCustomValidation = new NetTcpBinding(SecurityMode.Transport);
            string addressForCustomValidation = "net.tcp://localhost:10000/WCFService";
            bindingForCustomValidation.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;

            ServiceHost hostForCustomValidation = new ServiceHost(typeof(Service));
            hostForCustomValidation.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;
            hostForCustomValidation.Credentials.ClientCertificate.Authentication.CustomCertificateValidator = new CustomValidator();
            hostForCustomValidation.Credentials.ClientCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
            hostForCustomValidation.AddServiceEndpoint(typeof(IContract), bindingForCustomValidation, addressForCustomValidation);
            hostForCustomValidation.Credentials.ServiceCertificate.SetCertificate("CN=srv", StoreLocation.LocalMachine, StoreName.My);
            hostForCustomValidation.Open();

            Console.WriteLine("WCFService is opened. Press <enter> to finish...");
            Console.ReadLine();

            host.Close();
        }
开发者ID:LudiMajkan,项目名称:SIBUKI,代码行数:31,代码来源:Program.cs

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

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

示例4: NCMWindowsAuthInfoService

 public NCMWindowsAuthInfoService(string username, string password)
 {
     _endpoint = Settings.Default.NCMWindowsEndpointPath;
     _endpointConfigName = "NCMWindowsTcpBinding_InformationServicev2";
     _binding = new NetTcpBinding("Windows");
     _credentials = new WindowsCredential(username, password);
 }
开发者ID:rbramwell,项目名称:OrionSDK,代码行数:7,代码来源:NCMWindowsAuthInfoService.cs

示例5: Main

		static void Main()
		{
			// только не null, ибо возникнет исключение
			//var baseAddress = new Uri("http://localhost:8002/MyService");
			var host = new ServiceHost(typeof(MyContractClient));//, baseAddress);

			host.Open();

			//var otherBaseAddress = new Uri("http://localhost:8001/");
			var otherHost = new ServiceHost(typeof(MyOtherContractClient));//, otherBaseAddress);
			var wsBinding = new BasicHttpBinding();
			var tcpBinding = new NetTcpBinding();
			otherHost.AddServiceEndpoint(typeof(IMyOtherContract), wsBinding, "http://localhost:8001/MyOtherService");
			otherHost.AddServiceEndpoint(typeof(IMyOtherContract), tcpBinding, "net.tcp://localhost:8003/MyOtherService");

			//AddHttpGetMetadata(otherHost);
			AddMexEndpointMetadata(otherHost);

			otherHost.Open();


			// you can access http://localhost:8002/MyService
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new Host());

			otherHost.Close();

			host.Close();

			// you can not access http://localhost:8002/MyService
		}
开发者ID:Helen1987,项目名称:edu,代码行数:32,代码来源:Program.cs

示例6: Form1

        public Form1()
        {
            InitializeComponent();
            IntPtr dummyHandle = Handle;

            lvMission.DoubleBuffer(true);
            lvNDock.DoubleBuffer(true);
            lvMission.LoadColumnWithOrder(Properties.Settings.Default.MissionColumnWidth);
            lvNDock.LoadColumnWithOrder(Properties.Settings.Default.DockColumnWidth);

            var host = new RemoteHost(this);
            servHost = new ServiceHost(host);
            if (Properties.Settings.Default.NetTcp)
            {
                var bind = new NetTcpBinding(SecurityMode.None);
                bind.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
                servHost.AddServiceEndpoint(typeof(KCB.RPC.IUpdateNotification), bind, new Uri("net.tcp://localhost/kcb-update-channel"));
                servHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new HogeFugaValidator();
                servHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = System.ServiceModel.Security.UserNamePasswordValidationMode.Custom;
                Debug.WriteLine("Protocol:Net.Tcp");
                bTcpMode = true;
            }
            else
            {
                servHost.AddServiceEndpoint(typeof(KCB.RPC.IUpdateNotification), new NetNamedPipeBinding(), new Uri("net.pipe://localhost/kcb-update-channel"));
                Debug.WriteLine("Protocol:Net.Pipe");
            }
            servHost.Open();

            //起動し終えたのでシグナル状態へ
            Program._mutex.ReleaseMutex();

        }
开发者ID:lscyane,项目名称:KCBr,代码行数:33,代码来源:Form1.cs

示例7: GetBinding

 protected override Binding GetBinding()
 {
     var binding = new NetTcpBinding(SecurityMode.None);
     binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
     binding.ReliableSession.Enabled = true;
     return binding;
 }
开发者ID:Turntwo,项目名称:nvents,代码行数:7,代码来源:TcpEventEventServiceHost.cs

示例8: GetSaludo

        public string GetSaludo()
        {
            Trace.TraceInformation("Accediendo al servicio interno...");

              Trace.TraceInformation("Intentando crear el proxy del servicio interno...");

              string pid = Process.GetCurrentProcess().Id.ToString();
              string ppid = Process.GetCurrentProcess().ProcessName;

              string wip =
            RoleEnvironment.Roles["HolaAzureWorker"].Instances[0]
              .InstanceEndpoints["InternalWorker"].IPEndpoint.ToString();

              Trace.TraceInformation(wip);

              var serviceAddress = new Uri(string.Format("net.tcp://{0}/{1}", wip, "helloservice"));
              var endpointAddress = new EndpointAddress(serviceAddress);
              var binding = new NetTcpBinding(SecurityMode.None);

              var service = ChannelFactory<IWorkerInternalService>.CreateChannel(binding, endpointAddress);

              //  var service = WebRole.factory.CreateChannel();

              string hora = service.GetInformacion();

              //  como hago para obtener una propiedad desde la clase web role
              Trace.TraceInformation("Funcionando...a punto de saludar...");
              return string.Format("Hola Mundo Azure!! {0}", hora);
        }
开发者ID:ethedy,项目名称:EjemplosFS,代码行数:29,代码来源:HolaService.svc.cs

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

示例10: DefaultValues

		public void DefaultValues ()
		{
			var n = new NetTcpBinding ();
			Assert.AreEqual (HostNameComparisonMode.StrongWildcard, n.HostNameComparisonMode, "#1");
			Assert.AreEqual (10, n.ListenBacklog, "#2");
			Assert.AreEqual (false, n.PortSharingEnabled, "#3");

			var tr = n.CreateBindingElements ().Find<TcpTransportBindingElement> ();
			Assert.IsNotNull (tr, "#tr1");
			Assert.AreEqual (false, tr.TeredoEnabled, "#tr2");
			Assert.AreEqual ("net.tcp", tr.Scheme, "#tr3");

			Assert.IsFalse (n.TransactionFlow, "#4");
			var tx = n.CreateBindingElements ().Find<TransactionFlowBindingElement> ();
			Assert.IsNotNull (tx, "#tx1");

			Assert.AreEqual (SecurityMode.Transport, n.Security.Mode, "#sec1");
			Assert.AreEqual (ProtectionLevel.EncryptAndSign, n.Security.Transport.ProtectionLevel, "#sec2");
			Assert.AreEqual (TcpClientCredentialType.Windows/*huh*/, n.Security.Transport.ClientCredentialType, "#sec3");

			var bc = n.CreateBindingElements ();
			Assert.AreEqual (4, bc.Count, "#bc1");
			Assert.AreEqual (typeof (TransactionFlowBindingElement), bc [0].GetType (), "#bc2");
			Assert.AreEqual (typeof (BinaryMessageEncodingBindingElement), bc [1].GetType (), "#bc3");
			Assert.AreEqual (typeof (WindowsStreamSecurityBindingElement), bc [2].GetType (), "#bc4");
			Assert.AreEqual (typeof (TcpTransportBindingElement), bc [3].GetType (), "#bc5");
			
			Assert.IsFalse (n.CanBuildChannelFactory<IRequestChannel> (), "#cbf1");
			Assert.IsFalse (n.CanBuildChannelFactory<IOutputChannel> (), "#cbf2");
			Assert.IsFalse (n.CanBuildChannelFactory<IDuplexChannel> (), "#cbf3");
			Assert.IsTrue (n.CanBuildChannelFactory<IDuplexSessionChannel> (), "#cbf4");
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:32,代码来源:NetTcpBindingTest.cs

示例11: Window

        public Window()
        {
            InitializeComponent();
            _um6Driver = new Um6Driver("COM1", 115200);
            _um6Driver.Init();
            _servoDriver = new ServoDriver();
            _updateTimer = new System.Timers.Timer(50);
            _updateTimer.Elapsed += _updateTimer_Elapsed;
            _cameraDriver = new CameraDriver(this.Handle.ToInt64());
            _cameraDriver.Init(pictureBox.Handle.ToInt64());
            _cameraDriver.CameraCapture += _cameraDriver_CameraCapture;

            // initialize the service
            //_host = new ServiceHost(typeof(SatService));
            NetTcpBinding binding = new NetTcpBinding();
            binding.MaxReceivedMessageSize = 20000000;
            binding.MaxBufferPoolSize = 20000000;
            binding.MaxBufferSize = 20000000;
            binding.Security.Mode = SecurityMode.None;
            _service = new SatService(_cameraDriver);
            _host = new ServiceHost(_service);
            _host.AddServiceEndpoint(typeof(ISatService),
                                   binding,
                                   "net.tcp://localhost:8000");
            _host.Open();

            _stabPitchServo = 6000;
            _stabYawServo = 6000;
        }
开发者ID:nimski,项目名称:SatCamp,代码行数:29,代码来源:Window.cs

示例12: ServiceContract_TypedProxy_AsyncTask_CallbackReturn

    public static void ServiceContract_TypedProxy_AsyncTask_CallbackReturn()
    {
        DuplexChannelFactory<IWcfDuplexTaskReturnService> factory = null;
        Guid guid = Guid.NewGuid();

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

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

        try
        {
            factory = new DuplexChannelFactory<IWcfDuplexTaskReturnService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address));
            IWcfDuplexTaskReturnService serviceProxy = factory.CreateChannel();

            Task<Guid> task = serviceProxy.Ping(guid);

            Guid returnedGuid = task.Result;

            Assert.Equal(guid, returnedGuid);

            factory.Close();
        }
        finally
        {
            if (factory != null && factory.State != CommunicationState.Closed)
            {
                factory.Abort();
            }
        }
    }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:32,代码来源:TypedProxyDuplexTests.cs

示例13: DuplexClientBaseOfT_OverNetTcp_Synchronous_Call

    public static void DuplexClientBaseOfT_OverNetTcp_Synchronous_Call()
    {
        DuplexClientBase<IWcfDuplexService> duplexService = null;
        Guid guid = Guid.NewGuid();

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

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

            duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_Callback_Address));
            IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel();

            // Ping on another thread.
            Task.Run(() => proxy.Ping(guid));
            Guid returnedGuid = callbackService.CallbackGuid;

            Assert.True(guid == returnedGuid, 
                string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid)); 

            ((ICommunicationObject)duplexService).Close();
        }
        finally
        {
            if (duplexService != null && duplexService.State != CommunicationState.Closed)
            {
                duplexService.Abort();
            }
        }
    }
开发者ID:huoxudong125,项目名称:wcf,代码行数:33,代码来源:DuplexClientBaseTests.cs

示例14: AcceptChannelTest

        private static void AcceptChannelTest()
        {
            var binding = new NetTcpBinding();
            var listener = binding.Start(address);
            var connections = from channel in listener.GetChannels()
                           select new
                           {
                               Messages = channel.GetMessages(),
                               Response = channel.GetConsumer()
                           };

            connections.Subscribe(item =>
            {
                item.Response.Publish(Message.CreateMessage(binding.MessageVersion, "Test", "Echo:" + "Connected"));

                /*
                      (from message in channel.Messages
                       let input = message.GetBody<string>()
                       from response in new[] { Message.CreateMessage(version, "", "Echo:" + input) }
                       select response)
                      .Subscribe(channel.Response);

                 */
                item.Messages.Subscribe((message) =>
                {
                    var input = message.GetBody<string>();
                    var output = Message.CreateMessage(binding.MessageVersion, "", "Echo:" + input);
                    item.Response.Publish(output);
                });
            });
        }
开发者ID:headinthebox,项目名称:IoFx,代码行数:31,代码来源:Program.cs

示例15: Connect

        public bool Connect(ClientCrawlerInfo clientCrawlerInfo)
        {
            try
            {
                var site = new InstanceContext(this);

                var binding = new NetTcpBinding(SecurityMode.None);
                //var address = new EndpointAddress("net.tcp://localhost:22222/chatservice/");

                var address = new EndpointAddress("net.tcp://193.124.113.235:22222/chatservice/");
                var factory = new DuplexChannelFactory<IRemoteCrawler>(site, binding, address);

                proxy = factory.CreateChannel();
                ((IContextChannel)proxy).OperationTimeout = new TimeSpan(1, 0, 10);

                clientCrawlerInfo.ClientIdentifier = _singletoneId;
                proxy.Join(clientCrawlerInfo);

                return true;
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error happened" + ex.Message);
                return false;
            }
        }
开发者ID:8ezhikov,项目名称:Git4Life,代码行数:27,代码来源:ProxySingletone.cs


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