Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            if (AnyIpAddress == false)
            {
                for (int _ipadrs = 0; _ipadrs < IpAddresses.Length; _ipadrs++)
                {
                    this.Start(IpAddresses[_ipadrs]);
                }
            }
            else
            {
                this.Start(HostName);
            }

            var _ipOrLocalHost = (AnyIpAddress == false) ? IpAddresses[0] : "localhost";
            {
                var _urlBehavior = String.Format("http://{0}:{1}/{2}", _ipOrLocalHost, BehaviorPort, ServiceName);

                ServiceThrottlingBehavior _throttling = ServerHost.Description.Behaviors.Find <ServiceThrottlingBehavior>();
                if (_throttling == null)
                {
                    _throttling = new ServiceThrottlingBehavior
                    {
                        MaxConcurrentCalls     = int.MaxValue,
                        MaxConcurrentSessions  = int.MaxValue,
                        MaxConcurrentInstances = int.MaxValue
                    };

                    ServerHost.Description.Behaviors.Add(_throttling);
                }

                //ServiceDebugBehavior _debugging = ServerHost.Description.Behaviors.Find<ServiceDebugBehavior>();
                //if (_debugging == null)
                //{
                //    _debugging = new ServiceDebugBehavior();
                //    _debugging.IncludeExceptionDetailInFaults = true;

                //    ServerHost.Description.Behaviors.Add(_debugging);
                //}

                ServiceMetadataBehavior _metadata = ServerHost.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (_metadata == null)
                {
                    _metadata = new ServiceMetadataBehavior
                    {
                        HttpGetUrl     = new Uri(_urlBehavior),
                        HttpGetEnabled = true
                    };

                    ServerHost.Description.Behaviors.Add(_metadata);
                }

                this.BehaviorUrl = _urlBehavior;
                ServerHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), _urlBehavior);
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ip_address_or_host_name"></param>
        /// <param name="binding_name">wcf 바인딩 명칭 (ex)net.tcp</param>
        /// <param name="service_port">wcf접속시 연결 할 port번호</param>
        public void Start(string ip_address_or_host_name, string binding_name, int service_port)
        {
            lock (SyncRoot)
            {
                Binding _binding;
                var     _address = String.Format("://{0}:{1}/{2}", ip_address_or_host_name, service_port, ServiceName);

                if (binding_name.ToLower() == "WSHttpBinding".ToLower())
                {
                    _address = "http" + _address;

                    WSHttpBinding _binding2 = new WSHttpBinding();
                    {
                        _binding2.TransactionFlow = false;

                        _binding2.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                        _binding2.Security.Transport.ProxyCredentialType  = HttpProxyCredentialType.None;
                        _binding2.Security.Mode = SecurityMode.None;

                        _binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                        _binding2.MaxBufferPoolSize      *= MaxBufferPoolSize;

                        _binding2.ReaderQuotas = ReaderQuotas;
                    }

                    _binding = _binding2;
                }
                else if (binding_name.ToLower() == "WSDualHttpBinding".ToLower())
                {
                    _address = "http" + _address;

                    WSDualHttpBinding _binding2 = new WSDualHttpBinding();
                    {
                        _binding2.TransactionFlow = false;

                        _binding2.Security.Message.ClientCredentialType = MessageCredentialType.None;
                        _binding2.Security.Mode = WSDualHttpSecurityMode.None;

                        _binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                        _binding2.MaxBufferPoolSize      *= MaxBufferPoolSize;

                        _binding2.ReaderQuotas = ReaderQuotas;
                    }

                    _binding = _binding2;
                }
                else if (binding_name.ToLower() == "NetMsmqBinding".ToLower())
                {
                    _address = String.Format("net.msmq://{0}/private/{1}", ip_address_or_host_name, ServiceName);

                    NetMsmqBinding _binding2 = new NetMsmqBinding();
                    {
                        _binding2.Security.Transport.MsmqAuthenticationMode = MsmqAuthenticationMode.None;
                        _binding2.Security.Transport.MsmqProtectionLevel    = System.Net.Security.ProtectionLevel.None;

                        _binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                        _binding2.MaxBufferPoolSize      *= MaxBufferPoolSize;

                        _binding2.SendTimeout    = SendTimeout;
                        _binding2.ReceiveTimeout = ReceiveTimeout;

                        _binding2.ReaderQuotas = ReaderQuotas;
                    }

                    _binding = _binding2;
                }
                else if (binding_name.ToLower() == "NetNamedPipeBinding".ToLower())
                {
                    _address = "net.pipe" + _address;

                    NetNamedPipeBinding _binding2 = new NetNamedPipeBinding();
                    {
                        _binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                        _binding2.MaxBufferPoolSize      *= MaxBufferPoolSize;

                        _binding2.SendTimeout    = SendTimeout;
                        _binding2.ReceiveTimeout = ReceiveTimeout;

                        _binding2.ReaderQuotas = ReaderQuotas;
                    }

                    _binding = _binding2;
                }
                //else if (_binding_name.ToLower() == "NetPeerTcpBinding".ToLower())
                //{
                //    _address = "net.peer" + _address;

                //    NetPeerTcpBinding _binding2 = new NetPeerTcpBinding();
                //    {
                //        _binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                //        _binding2.MaxBufferPoolSize *= MaxBufferPoolSize;

                //        _binding2.SendTimeout = SendTimeout;
                //        _binding2.ReceiveTimeout = ReceiveTimeout;

                //        _binding2.ReaderQuotas = ReaderQuotas;
                //    }

                //    _binding = _binding2;
                //}
                else if (binding_name.ToLower() == "net.tcp".ToLower())
                {
                    if (IsPortSharing == true)
                    {
                        service_port = SharingPort;
                    }

                    _address = String.Format("net.tcp://{0}:{1}/{2}", ip_address_or_host_name, service_port, ServiceName);

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

                        _binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                        _binding2.MaxBufferPoolSize      *= MaxBufferPoolSize;

                        _binding2.SendTimeout    = SendTimeout;
                        _binding2.ReceiveTimeout = ReceiveTimeout;

                        _binding2.ReaderQuotas       = ReaderQuotas;
                        _binding2.PortSharingEnabled = IsPortSharing;
                    }

                    _binding = _binding2;
                }
                else if (binding_name.ToLower() == "BasicHttpBinding".ToLower())
                {
                    _address = "http" + _address;

                    BasicHttpBinding _binding2 = new BasicHttpBinding();
                    {
                        _binding2.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

                        _binding2.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
                        _binding2.Security.Mode = BasicHttpSecurityMode.None;

                        _binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                        _binding2.MaxBufferPoolSize      *= MaxBufferPoolSize;

                        _binding2.ReaderQuotas = ReaderQuotas;
                    }

                    _binding = _binding2;
                }
                else if (binding_name.ToLower() == "WebHttpBinding".ToLower())
                {
                    _address = "http" + _address;

                    WebHttpBinding _binding2 = new WebHttpBinding();
                    {
                        _binding2.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

                        _binding2.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
                        _binding2.Security.Mode = WebHttpSecurityMode.None;

                        _binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                        _binding2.MaxBufferPoolSize      *= MaxBufferPoolSize;

                        _binding2.ReaderQuotas = ReaderQuotas;
                    }

                    _binding = _binding2;
                }
                else
                {
                    _address = "http" + _address;

                    // Create a custom binding that contains two binding elements.
                    ReliableSessionBindingElement _reliableSession = new ReliableSessionBindingElement
                    {
                        InactivityTimeout = TimeSpan.FromDays(7),
                        Ordered           = true
                    };

                    HttpTransportBindingElement _httpTransport = new HttpTransportBindingElement
                    {
                        AuthenticationScheme   = System.Net.AuthenticationSchemes.Anonymous,
                        HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
                    };

                    CustomBinding _binding2 = new CustomBinding(_reliableSession, _httpTransport);
                    {
                        //_binding2.MaxReceivedMessageSize *= MaxReceivedMessageSize;
                        //_binding2.MaxBufferPoolSize *= MaxBufferPoolSize;

                        _binding2.SendTimeout    = SendTimeout;
                        _binding2.ReceiveTimeout = ReceiveTimeout;

                        //_binding2.ReaderQuotas = ReaderQuotas;
                    }

                    _binding = _binding2;
                }

                this.WcfAddress += _address + " ";
                ServerHost.AddServiceEndpoint(InterfaceType, _binding, _address);
            }
        }