Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="receivedCallback"></param>
        /// <param name="connectTimeout">建立连接和传送数据的超时间</param>
        /// <param name="receiveTimeout">保持连接的情况下,空闲超时触发Closing事件</param>
        /// <param name="inactivityTimeout">连接断开的情况下,空闲超时触发Faulted事件,要小于receiveTimeout时间间隔</param>
        public void Bind(string ip, int port, Action <string, byte[]> receivedCallback, int connectTimeout, TimeSpan receiveTimeout, int inactivityTimeout)
        {
            var setting = new BindingBehaviorSetting(ip, port);

            _connectTimeout           = new TimeSpan(0, 0, connectTimeout);
            _receiveTimeout           = receiveTimeout;
            _inactivityTimeout        = new TimeSpan(0, 0, inactivityTimeout);
            setting.ConnectTimeout    = _connectTimeout;
            setting.ReceiveTimeout    = _receiveTimeout;
            setting.InactivityTimeout = _inactivityTimeout;
            Binding binding = CreateBinding(BindingType.NetTcpBinding, setting);

            Bind(ip, port, binding, receivedCallback);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bindingType"></param>
        /// <param name="setting"></param>
        /// <returns></returns>
        public Binding CreateBinding(BindingType bindingType, BindingBehaviorSetting setting)
        {
            Binding bindinginstance = null;

            switch (bindingType)
            {
            case BindingType.BasicHttpBinding:
                BasicHttpBinding basicHttp = new BasicHttpBinding();
                basicHttp.MaxReceivedMessageSize = MaxReceivedSize;
                bindinginstance = basicHttp;
                break;

            case BindingType.NetNamedPipeBinding:
                NetNamedPipeBinding wsPipe = new NetNamedPipeBinding();
                wsPipe.MaxReceivedMessageSize = MaxReceivedSize;
                bindinginstance = wsPipe;
                break;

            case BindingType.NetPeerTcpBinding:
                NetPeerTcpBinding wsPeerTcp = new NetPeerTcpBinding();
                wsPeerTcp.MaxReceivedMessageSize = MaxReceivedSize;
                bindinginstance = wsPeerTcp;
                break;

            case BindingType.NetTcpBinding:
                NetTcpBinding wsTcp = new NetTcpBinding();
                wsTcp.MaxReceivedMessageSize            = MaxReceivedSize;
                wsTcp.ReliableSession.Enabled           = true;
                wsTcp.ReliableSession.InactivityTimeout = setting.InactivityTimeout;
                wsTcp.Security.Mode  = SecurityMode.None;
                wsTcp.OpenTimeout    = setting.ConnectTimeout;
                wsTcp.CloseTimeout   = setting.ConnectTimeout;
                wsTcp.SendTimeout    = setting.SendTimeout;
                wsTcp.ReceiveTimeout = setting.ReceiveTimeout;
                bindinginstance      = wsTcp;
                break;

            case BindingType.WsDualHttpBinding:
                WSDualHttpBinding wsDual = new WSDualHttpBinding();
                wsDual.MaxReceivedMessageSize = MaxReceivedSize;
                bindinginstance = wsDual;
                break;

            case BindingType.WsFederationHttpBinding:
                WSFederationHttpBinding wsFederation = new WSFederationHttpBinding();
                wsFederation.MaxReceivedMessageSize = MaxReceivedSize;
                bindinginstance = wsFederation;
                break;

            case BindingType.WsHttpBinding:
                WSHttpBinding wsHttp = new WSHttpBinding(SecurityMode.None);
                wsHttp.MaxReceivedMessageSize = MaxReceivedSize;
                wsHttp.Security.Message.ClientCredentialType   = MessageCredentialType.Windows;
                wsHttp.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                bindinginstance = wsHttp;
                break;

            default:
                throw new ArgumentOutOfRangeException("bindingType");
            }
            return(bindinginstance);
        }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 public WcfServiceProxy(BindingBehaviorSetting setting)
 {
     _setting = setting;
 }
Esempio n. 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="bindingType"></param>
 /// <param name="setting"></param>
 /// <returns></returns>
 public Binding CreateBinding(BindingType bindingType, BindingBehaviorSetting setting)
 {
     Binding bindinginstance = null;
     switch (bindingType)
     {
         case BindingType.BasicHttpBinding:
             BasicHttpBinding basicHttp = new BasicHttpBinding();
             basicHttp.MaxReceivedMessageSize = MaxReceivedSize;
             bindinginstance = basicHttp;
             break;
         case BindingType.NetNamedPipeBinding:
             NetNamedPipeBinding wsPipe = new NetNamedPipeBinding();
             wsPipe.MaxReceivedMessageSize = MaxReceivedSize;
             bindinginstance = wsPipe;
             break;
         case BindingType.NetPeerTcpBinding:
             NetPeerTcpBinding wsPeerTcp = new NetPeerTcpBinding();
             wsPeerTcp.MaxReceivedMessageSize = MaxReceivedSize;
             bindinginstance = wsPeerTcp;
             break;
         case BindingType.NetTcpBinding:
             NetTcpBinding wsTcp = new NetTcpBinding();
             wsTcp.MaxReceivedMessageSize = MaxReceivedSize;
             wsTcp.ReliableSession.Enabled = true;
             wsTcp.ReliableSession.InactivityTimeout = setting.InactivityTimeout;
             wsTcp.Security.Mode = SecurityMode.None;
             wsTcp.OpenTimeout = setting.ConnectTimeout;
             wsTcp.CloseTimeout = setting.ConnectTimeout;
             wsTcp.SendTimeout = setting.SendTimeout;
             wsTcp.ReceiveTimeout = setting.ReceiveTimeout;
             bindinginstance = wsTcp;
             break;
         case BindingType.WsDualHttpBinding:
             WSDualHttpBinding wsDual = new WSDualHttpBinding();
             wsDual.MaxReceivedMessageSize = MaxReceivedSize;
             bindinginstance = wsDual;
             break;
         case BindingType.WsFederationHttpBinding:
             WSFederationHttpBinding wsFederation = new WSFederationHttpBinding();
             wsFederation.MaxReceivedMessageSize = MaxReceivedSize;
             bindinginstance = wsFederation;
             break;
         case BindingType.WsHttpBinding:
             WSHttpBinding wsHttp = new WSHttpBinding(SecurityMode.None);
             wsHttp.MaxReceivedMessageSize = MaxReceivedSize;
             wsHttp.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
             wsHttp.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
             bindinginstance = wsHttp;
             break;
         default:
             throw new ArgumentOutOfRangeException("bindingType");
     }
     return bindinginstance;
 }
Esempio n. 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="port"></param>
 /// <param name="receivedCallback"></param>
 /// <param name="connectTimeout">建立连接和传送数据的超时间</param>
 /// <param name="receiveTimeout">保持连接的情况下,空闲超时触发Closing事件</param>
 /// <param name="inactivityTimeout">连接断开的情况下,空闲超时触发Faulted事件,要小于receiveTimeout时间间隔</param>
 public void Bind(string ip, int port, Action<string, byte[]> receivedCallback, int connectTimeout, TimeSpan receiveTimeout, int inactivityTimeout)
 {
     var setting = new BindingBehaviorSetting(ip, port);
     _connectTimeout = new TimeSpan(0, 0, connectTimeout);
     _receiveTimeout = receiveTimeout;
     _inactivityTimeout = new TimeSpan(0, 0, inactivityTimeout);
     setting.ConnectTimeout = _connectTimeout;
     setting.ReceiveTimeout = _receiveTimeout;
     setting.InactivityTimeout = _inactivityTimeout;
     Binding binding = CreateBinding(BindingType.NetTcpBinding, setting);
     Bind(ip, port, binding, receivedCallback);
 }
Esempio n. 6
0
 /// <summary>
 /// 
 /// </summary>
 public WcfServiceProxy(BindingBehaviorSetting setting)
 {
     _setting = setting;
 }