예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            BindingString = "net.tcp://localhost:9008/TestWCFService";
            Host          = new ServiceHost(typeof(Service));

            NetTcpBinding oBinding = new NetTcpBinding();

            XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();

            myReaderQuotas.MaxStringContentLength = Int32.MaxValue;
            myReaderQuotas.MaxArrayLength         = Int32.MaxValue;
            myReaderQuotas.MaxDepth = Int32.MaxValue;


            oBinding.GetType().GetProperty("ReaderQuotas").SetValue(oBinding, myReaderQuotas, null);
            oBinding.SendTimeout            = new TimeSpan(0, 1, 0);
            oBinding.MaxBufferSize          = Int32.MaxValue;
            oBinding.MaxReceivedMessageSize = Int32.MaxValue;
            oBinding.Security.Mode          = SecurityMode.None;


            Host.AddServiceEndpoint(typeof(IService), oBinding, BindingString);
            Host.Opened += new EventHandler(Host_Opened);
            Host.Closed += new EventHandler(Host_Closed);


            foreach (ServiceEndpoint ep in Host.Description.Endpoints)
            {
                foreach (OperationDescription op in ep.Contract.Operations)
                {
                    DataContractSerializerOperationBehavior dataContractBehavior =
                        op.Behaviors.Find <DataContractSerializerOperationBehavior>()
                        as DataContractSerializerOperationBehavior;
                    if (dataContractBehavior != null)
                    {
                        dataContractBehavior.MaxItemsInObjectGraph = Int32.MaxValue;
                    }
                }
            }
            try
            {
                Host.Open();
                Console.WriteLine("");
            }
            catch (Exception ex)
            {
            }
        }
예제 #2
0
        public iProxy(string strIP, string strPort)
        {
            try
            {
                if (EventLibCallback.oCallBack == null)
                {
                    EventLibrary.EventLibCallback.oCallBack = new EventLibrary.EventLib();
                }


                //EndpointAddress address = new EndpointAddress("net.tcp://" + strIP + ":" + strPort + "/TestWCFService");
                EndpointAddress           address        = new EndpointAddress("net.tcp://localhost:9008/TestWCFService");
                XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();
                myReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                myReaderQuotas.MaxArrayLength         = Int32.MaxValue;
                myReaderQuotas.MaxDepth = Int32.MaxValue;

                NetTcpBinding oBinding = new NetTcpBinding();

                oBinding.GetType().GetProperty("ReaderQuotas").SetValue(oBinding, myReaderQuotas, null);
                oBinding.ReceiveTimeout         = new TimeSpan(1, 0, 0);
                oBinding.MaxBufferSize          = Int32.MaxValue;
                oBinding.MaxReceivedMessageSize = Int32.MaxValue;
                oBinding.Security.Mode          = SecurityMode.None;

                DuplexChannelFactory <IService> oCF = new DuplexChannelFactory <IService>(EventLibrary.EventLibCallback.oCallBack, oBinding, address);
                foreach (OperationDescription op in oCF.Endpoint.Contract.Operations)
                {
                    var dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>();
                    if (dataContractBehavior != null)
                    {
                        dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                    }
                }

                _Service = oCF.CreateChannel();

                oCF.Opened += new EventHandler(oCF_Opened);
                oCF.Closed += new EventHandler(oCF_Closed);

                ((IContextChannel)_Service).OperationTimeout = new TimeSpan(0, 20, 0);
                Status = true;
            }
            catch (Exception ex)
            {
                Status = false;
            }
        }
예제 #3
0
        private NetTcpBinding CreateTcpBinding()
        {
            NetTcpBinding tcpBinding = new NetTcpBinding();

            System.ServiceModel.Channels.BindingElementCollection bElementCollection = tcpBinding.CreateBindingElements();

            tcpBinding.Name                   = "SeymourSkinner";
            tcpBinding.CloseTimeout           = TimeSpan.FromHours(2); // new TimeSpan(1, 0, 0); // 1 hora
            tcpBinding.OpenTimeout            = TimeSpan.FromHours(2); // new TimeSpan(1, 0, 0); // 1 hora
            tcpBinding.ReceiveTimeout         = TimeSpan.FromHours(2); // new TimeSpan(1, 0, 0); // 1 hora
            tcpBinding.SendTimeout            = TimeSpan.FromHours(2); // new TimeSpan(1, 0, 0); // 1 hora
            tcpBinding.MaxBufferPoolSize      = 2147483647;
            tcpBinding.MaxBufferSize          = 2147483647;
            tcpBinding.MaxReceivedMessageSize = 2147483647;

            tcpBinding.ReliableSession.InactivityTimeout = new TimeSpan(1, 0, 0);
            tcpBinding.Security.Mode = SecurityMode.None;

            System.ServiceModel.Channels.TcpTransportBindingElement tcp = bElementCollection.Find <System.ServiceModel.Channels.TcpTransportBindingElement>();
            tcp.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 500;
            tcp.ConnectionPoolSettings.LeaseTimeout = TimeSpan.MaxValue;
            tcp.ConnectionPoolSettings.IdleTimeout  = TimeSpan.MaxValue;
            tcp.ChannelInitializationTimeout        = TimeSpan.MaxValue;
            tcp.ConnectionBufferSize   = int.MaxValue;
            tcp.MaxBufferPoolSize      = long.MaxValue;
            tcp.MaxBufferSize          = int.MaxValue;
            tcp.MaxReceivedMessageSize = long.MaxValue;

            XmlDictionaryReaderQuotas quotas = tcpBinding.ReaderQuotas;

            quotas.MaxStringContentLength = int.MaxValue;
            quotas.MaxArrayLength         = int.MaxValue;
            quotas.MaxBytesPerRead        = int.MaxValue;
            quotas.MaxDepth = int.MaxValue;
            quotas.MaxNameTableCharCount = int.MaxValue;

            tcpBinding.GetType().GetProperty("ReaderQuotas").SetValue(tcpBinding, quotas, null);

            return(tcpBinding);
        }
예제 #4
0
        public void ServiceStart()
        {
            baseAddress = new Uri("net.tcp://localhost:8018/Job/MessageService");
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode          = SecurityMode.Message;
            binding.MaxReceivedMessageSize = 2147483647;
            binding.CloseTimeout           = TimeSpan.MaxValue;
            binding.ReceiveTimeout         = TimeSpan.MaxValue;

            XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();

            myReaderQuotas.MaxStringContentLength = 2147483647;
            binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, myReaderQuotas, null);
            host = new ServiceHost(typeof(MessageService));
            try
            {
                host.AddServiceEndpoint(typeof(IMessageService), binding, baseAddress);
                host.Open();

                Console.WriteLine("Serveur started");
                Console.WriteLine("Type quit to stop the app");
                string command = "";
                while (command != "quit")
                {
                    command = Console.ReadLine();
                    if (command != "")
                    {
                        Console.WriteLine("Unknown command, type \"quit\" to stop the app");
                    }
                }
                host.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception rencontrée : {ex.Message}");
            }
        }