예제 #1
0
 internal NameSettings(NameSettings nameSettings)
 {
     this.uri             = nameSettings.uri;
     this.displayName     = nameSettings.DisplayName;
     this.owner           = nameSettings.Owner;
     this.serviceSettings = new Microsoft.ServiceBus.ServiceSettings(nameSettings.ServiceSettings);
 }
 public HybridConnectionElement(BindingContext context, TcpRelayTransportBindingElement transportBindingElement, NameSettings nameSettings, TokenProvider tokenProvider)
 {
     this.context                 = context;
     this.nameSettings            = nameSettings;
     this.tokenProvider           = tokenProvider;
     this.transportBindingElement = transportBindingElement;
 }
예제 #3
0
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context)
            where TChannel : class, IChannel
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (typeof(TChannel) != typeof(IInputChannel))
            {
                throw new NotImplementedException(SRClient.UnsupportedChannelType(typeof(TChannel)));
            }
            NameSettings nameSetting = context.BindingParameters.Find <NameSettings>();

            if (nameSetting == null)
            {
                nameSetting = new NameSettings();
                context.BindingParameters.Add(nameSetting);
            }
            if (nameSetting.ServiceSettings.ListenerType == ListenerType.None)
            {
                nameSetting.ServiceSettings.ListenerType                  = (this.ConnectionMode == RelayedOnewayConnectionMode.Unicast ? ListenerType.Unicast : ListenerType.Multicast);
                nameSetting.ServiceSettings.TransportProtection           = (this.transportProtectionEnabled ? RelayTransportProtectionMode.EndToEnd : RelayTransportProtectionMode.None);
                nameSetting.ServiceSettings.RelayClientAuthenticationType = this.relayClientAuthenticationType;
            }
            return((IChannelListener <TChannel>)(new RelayedOnewayChannelListener(context, this)));
        }
예제 #4
0
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context)
            where TChannel : class, IChannel
        {
            if (typeof(TChannel) != typeof(IReplyChannel))
            {
                ExceptionUtility exceptionUtility        = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           channelTypeNotSupported = Resources.ChannelTypeNotSupported;
                object[]         objArray = new object[] { typeof(TChannel) };
                throw exceptionUtility.ThrowHelperArgument("TChannel", Microsoft.ServiceBus.SR.GetString(channelTypeNotSupported, objArray));
            }
            NameSettings nameSetting = context.BindingParameters.Find <NameSettings>();

            if (nameSetting == null)
            {
                nameSetting = new NameSettings();
                context.BindingParameters.Add(nameSetting);
            }
            nameSetting.ServiceSettings.ListenerType                  = ListenerType.RelayedHttp;
            nameSetting.ServiceSettings.TransportProtection           = (this is HttpsRelayTransportBindingElement ? RelayTransportProtectionMode.EndToEnd : RelayTransportProtectionMode.None);
            nameSetting.ServiceSettings.RelayClientAuthenticationType = this.relayClientAuthenticationType;
            nameSetting.ServiceSettings.IsDynamic = this.IsDynamic;
            MessageEncodingBindingElement messageEncodingBindingElement = context.BindingParameters.Find <MessageEncodingBindingElement>();
            BindingContext bindingContext = this.CreateInnerListenerBindingContext(context);

            if (messageEncodingBindingElement != null)
            {
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            return((IChannelListener <TChannel>)(new RelayHttpTransportChannelListener(context, messageEncodingBindingElement, bindingContext.BuildInnerChannelListener <IReplyChannel>())));
        }
 public WebSocketRelayedConnectionElement(TokenProvider tokenProvider, SocketSecurityRole socketSecurityMode, BindingContext context, NameSettings nameSettings)
 {
     this.tokenProvider      = tokenProvider;
     this.SecurityMode       = socketSecurityMode;
     this.context            = context;
     this.nameSettings       = nameSettings;
     this.connectionListener = new WebSocketRelayedConnectionListener(this.tokenProvider, this.SecurityMode, this.nameSettings, context);
 }
예제 #6
0
 public WebSocketRelayedConnectionListener(TokenProvider tokenProvider, SocketSecurityRole socketSecurityMode, NameSettings nameSettings, BindingContext context)
 {
     this.tokenProvider            = tokenProvider;
     this.nameSettings             = nameSettings;
     this.serviceHost              = new ConfigurationlessServiceHost(this, new Uri[0]);
     this.innerConnectionStatus    = new ConnectionStatusBehavior();
     this.connectivitySettings     = context.BindingParameters.Find <ConnectivitySettings>();
     this.httpConnectivitySettings = context.BindingParameters.Find <HttpConnectivitySettings>();
 }
예제 #7
0
 public RelayedSocketListener(TokenProvider tokenProvider, NameSettings nameSettings, SocketSecurityRole socketSecurityMode, ConnectivitySettingsEndpointBehavior connectivitySettings)
 {
     this.tokenProvider      = tokenProvider;
     this.nameSettings       = nameSettings;
     this.socketSecurityMode = socketSecurityMode;
     this.serviceHost        = new ConfigurationlessServiceHost(this, new Uri[0]);
     this.connectionSessions = new Dictionary <string, RelayedConnectionSession>();
     this.socketQueue        = new InputQueue <Microsoft.ServiceBus.Channels.IConnection>();
     this.mutex = new object();
     this.innerConnectionStatus        = new ConnectionStatusBehavior();
     this.connectivitySettingsBehavior = connectivitySettings;
 }
        public static IRelayedOnewaySender CreateConnection(BindingContext context, RelayedOnewayTransportBindingElement transportBindingElement, Uri uri)
        {
            ConnectivitySettings connectivitySetting = context.BindingParameters.Find <ConnectivitySettings>();
            NameSettings         nameSetting         = context.BindingParameters.Find <NameSettings>();
            ConnectivityMode     connectivityMode    = (connectivitySetting != null ? connectivitySetting.Mode : ConnectivityModeHelper.SystemConnectivityMode);

            if (connectivityMode == ConnectivityMode.AutoDetect)
            {
                connectivityMode = NetworkDetector.DetectConnectivityModeForAutoDetect(uri);
            }
            if (connectivityMode != ConnectivityMode.Tcp)
            {
                return(new RelayedOnewayHttpSender(context, uri, nameSetting.ServiceSettings.TransportProtection == RelayTransportProtectionMode.EndToEnd));
            }
            return(new RelayedOnewayTcpSender(context, transportBindingElement, uri, nameSetting.ServiceSettings.TransportProtection == RelayTransportProtectionMode.EndToEnd, new EventTraceActivity()));
        }
예제 #9
0
        void System.ServiceModel.Description.IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
            NameSettings nameSetting = new NameSettings()
            {
                DisplayName = this.displayName
            };

            nameSetting.ServiceSettings.Discovery = this.discoveryType;
            nameSetting.ServiceSettings.RelayClientAuthenticationType = (this.allowUnauthenticatedAccess ? RelayClientAuthenticationType.None : RelayClientAuthenticationType.RelayAccessToken);
            nameSetting.ServiceSettings.TransportProtection           = (this.transportProtectionEnabled ? RelayTransportProtectionMode.EndToEnd : RelayTransportProtectionMode.None);
            if (this.PreserveRawHttp.HasValue)
            {
                nameSetting.ServiceSettings.PreserveRawHttp = this.PreserveRawHttp.Value;
            }
            bindingParameters.Add(nameSetting);
        }
예제 #10
0
        public RelayedSocketElement(BindingContext context, NameSettings nameSettings, TokenProvider tokenProvider, SocketSecurityRole socketSecurityMode)
        {
            this.context            = context;
            this.nameSettings       = nameSettings;
            this.tokenProvider      = tokenProvider;
            this.socketSecurityMode = socketSecurityMode;
            ConnectivitySettingsEndpointBehavior connectivitySettingsEndpointBehavior = null;
            ConnectivitySettings     connectivitySetting     = this.context.BindingParameters.Find <ConnectivitySettings>();
            HttpConnectivitySettings httpConnectivitySetting = this.context.BindingParameters.Find <HttpConnectivitySettings>();

            if (connectivitySetting != null || httpConnectivitySetting != null)
            {
                connectivitySettingsEndpointBehavior = new ConnectivitySettingsEndpointBehavior(connectivitySetting, httpConnectivitySetting);
            }
            this.connectionListener = new RelayedSocketListener(this.tokenProvider, this.nameSettings, this.socketSecurityMode, connectivitySettingsEndpointBehavior);
        }
예제 #11
0
        public HybridConnectionInitiator(BindingContext context, TcpRelayTransportBindingElement transportBindingElement, int bufferSize, TokenProvider tokenProvider, RelayTransportProtectionMode transportProtection)
        {
            this.bufferSize = bufferSize;
            NameSettings nameSetting = new NameSettings();

            nameSetting.ServiceSettings.TransportProtection = transportProtection;
            nameSetting.ServiceSettings.ListenerType        = ListenerType.HybridConnection;
            IConnectionElement relayedSocketElement = new RelayedSocketElement(context, nameSetting, tokenProvider, SocketSecurityRole.None);

            this.relayedSocketInitiator = (new DemuxSocketElement(relayedSocketElement, "relayed")).CreateInitiator(bufferSize);
            IConnectionElement demuxSocketElement = new DemuxSocketElement(relayedSocketElement, "direct");
            Binding            binding            = HybridConnectionElement.CreateDirectControlBindingElement(context, transportBindingElement, demuxSocketElement);

            this.directSocketInitiator = new DirectSocketInitiator(bufferSize, binding);
            this.connectionId          = Guid.NewGuid();
        }
예제 #12
0
        private BindingContext CreateInnerListenerBindingContext(BindingContext context)
        {
            BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = ClientMessageUtility.CreateInnerEncodingBindingElement(context);
            NameSettings nameSetting = context.BindingParameters.Find <NameSettings>();
            TcpRelayTransportBindingElement tcpRelayTransportBindingElement = new TcpRelayTransportBindingElement(this.RelayClientAuthenticationType)
            {
                ManualAddressing           = base.ManualAddressing,
                HostNameComparisonMode     = this.HostNameComparisonMode,
                MaxBufferPoolSize          = this.MaxBufferPoolSize,
                MaxBufferSize              = this.MaxBufferSize,
                MaxReceivedMessageSize     = this.MaxReceivedMessageSize,
                TransferMode               = System.ServiceModel.TransferMode.Streamed,
                TransportProtectionEnabled = nameSetting.ServiceSettings.TransportProtection != RelayTransportProtectionMode.None
            };

            tcpRelayTransportBindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 100;
            tcpRelayTransportBindingElement.IsDynamic = nameSetting.ServiceSettings.IsDynamic;
            BindingElement[] bindingElementArray = new BindingElement[] { binaryMessageEncodingBindingElement, tcpRelayTransportBindingElement };
            CustomBinding    customBinding       = new CustomBinding(bindingElementArray)
            {
                CloseTimeout   = context.Binding.CloseTimeout,
                Name           = context.Binding.Name,
                Namespace      = context.Binding.Namespace,
                OpenTimeout    = context.Binding.OpenTimeout,
                ReceiveTimeout = context.Binding.ReceiveTimeout,
                SendTimeout    = context.Binding.SendTimeout
            };
            BindingParameterCollection bindingParameterCollection = new BindingParameterCollection();

            foreach (object bindingParameter in context.BindingParameters)
            {
                if (bindingParameter is MessageEncodingBindingElement)
                {
                    continue;
                }
                bindingParameterCollection.Add(bindingParameter);
            }
            Uri sbUri = RelayedHttpUtility.ConvertToSbUri(context.ListenUriBaseAddress);

            return(new BindingContext(customBinding, bindingParameterCollection, sbUri, context.ListenUriRelativeAddress, context.ListenUriMode));
        }
예제 #13
0
        internal bool IsCompatible(NameSettings nameSettings)
        {
            if (this.uri == null && nameSettings.uri != null || this.uri != null && nameSettings.uri == null)
            {
                return(false);
            }
            bool flag = (this.uri != null ? false : nameSettings.uri == null);

            if (!flag)
            {
                string str         = this.uri.AbsoluteUri.TrimEnd(new char[] { '/' });
                string absoluteUri = nameSettings.uri.AbsoluteUri;
                char[] chrArray    = new char[] { '/' };
                flag = str.Equals(absoluteUri.TrimEnd(chrArray), StringComparison.OrdinalIgnoreCase);
            }
            bool flag1 = this.serviceSettings.IsCompatible(nameSettings.serviceSettings);

            if (flag)
            {
                return(flag1);
            }
            return(false);
        }
        private BindingElement BuildInnerBindingElement(BindingContext context)
        {
            SocketConnectionBindingElement socketConnectionBindingElement = null;
            NameSettings nameSetting = context.BindingParameters.Find <NameSettings>();
            NameSettings relayClientAuthenticationType = nameSetting;

            if (nameSetting == null)
            {
                relayClientAuthenticationType = new NameSettings();
                context.BindingParameters.Add(relayClientAuthenticationType);
            }
            relayClientAuthenticationType.ServiceSettings.TransportProtection           = (this.transportProtectionEnabled ? RelayTransportProtectionMode.EndToEnd : RelayTransportProtectionMode.None);
            relayClientAuthenticationType.ServiceSettings.RelayClientAuthenticationType = this.RelayClientAuthenticationType;
            relayClientAuthenticationType.ServiceSettings.IsDynamic = this.IsDynamic;
            TokenProvider tokenProvider = TokenProviderUtility.CreateTokenProvider(context);

            switch (this.relayedConnectionMode)
            {
            case TcpRelayConnectionMode.Relayed:
            {
                if (relayClientAuthenticationType.ServiceSettings.ListenerType != ListenerType.RelayedHttp)
                {
                    relayClientAuthenticationType.ServiceSettings.ListenerType = ListenerType.RelayedConnection;
                }
                ConnectivitySettings     connectivitySetting     = context.BindingParameters.Find <ConnectivitySettings>();
                HttpConnectivitySettings httpConnectivitySetting = context.BindingParameters.Find <HttpConnectivitySettings>();
                socketConnectionBindingElement = new SocketConnectionBindingElement(new ConnectivityModeConnectionElement(tokenProvider, (this.transportProtectionEnabled ? SocketSecurityRole.SslClient : SocketSecurityRole.None), context, relayClientAuthenticationType, connectivitySetting, httpConnectivitySetting));
                break;
            }

            case TcpRelayConnectionMode.Hybrid:
            {
                if (base.ChannelInitializationTimeout < TimeSpan.FromSeconds(60))
                {
                    base.ChannelInitializationTimeout = TimeSpan.FromSeconds(60);
                }
                relayClientAuthenticationType.ServiceSettings.ListenerType = ListenerType.DirectConnection;
                socketConnectionBindingElement = new SocketConnectionBindingElement(new HybridConnectionElement(context, this, relayClientAuthenticationType, tokenProvider));
                break;
            }

            default:
            {
                goto case TcpRelayConnectionMode.Relayed;
            }
            }
            socketConnectionBindingElement.ChannelInitializationTimeout        = base.ChannelInitializationTimeout;
            socketConnectionBindingElement.ConnectionBufferSize                = base.ConnectionBufferSize;
            socketConnectionBindingElement.ConnectionPoolSettings.GroupName    = this.ConnectionPoolSettings.GroupName;
            socketConnectionBindingElement.ConnectionPoolSettings.IdleTimeout  = this.ConnectionPoolSettings.IdleTimeout;
            socketConnectionBindingElement.ConnectionPoolSettings.LeaseTimeout = this.ConnectionPoolSettings.LeaseTimeout;
            socketConnectionBindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = this.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint;
            socketConnectionBindingElement.ExposeConnectionProperty   = base.ExposeConnectionProperty;
            socketConnectionBindingElement.HostNameComparisonMode     = base.HostNameComparisonMode;
            socketConnectionBindingElement.InheritBaseAddressSettings = base.InheritBaseAddressSettings;
            socketConnectionBindingElement.ListenBacklog          = this.ListenBacklog;
            socketConnectionBindingElement.ManualAddressing       = base.ManualAddressing;
            socketConnectionBindingElement.MaxBufferPoolSize      = this.MaxBufferPoolSize;
            socketConnectionBindingElement.MaxBufferSize          = base.MaxBufferSize;
            socketConnectionBindingElement.MaxOutputDelay         = base.MaxOutputDelay;
            socketConnectionBindingElement.MaxPendingAccepts      = base.MaxPendingAccepts;
            socketConnectionBindingElement.MaxPendingConnections  = base.MaxPendingConnections;
            socketConnectionBindingElement.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
            socketConnectionBindingElement.TransferMode           = base.TransferMode;
            socketConnectionBindingElement.TeredoEnabled          = false;
            return(socketConnectionBindingElement);
        }
예제 #15
0
        public ConnectivityModeConnectionElement(TokenProvider tokenProvider, SocketSecurityRole socketSecurityMode, BindingContext context, NameSettings nameSettings, ConnectivitySettings connectivitySettings, HttpConnectivitySettings httpConnectivitySettings)
        {
            this.tokenProvider = tokenProvider;
            this.SecurityMode  = socketSecurityMode;
            this.cache         = new ConnectivityModeCache(connectivitySettings, httpConnectivitySettings);
            if (context == null || !(context.ListenUriBaseAddress != null))
            {
                return;
            }
            InternalConnectivityMode internalConnectivityMode = this.cache.GetInternalConnectivityMode(context.ListenUriBaseAddress);

            switch (internalConnectivityMode)
            {
            case InternalConnectivityMode.Tcp:
            {
                this.connectionElement = new RelayedSocketElement(context, nameSettings, this.tokenProvider, this.SecurityMode);
                return;
            }

            case InternalConnectivityMode.Http:
            {
                this.connectionElement = new WebStreamRelayedConnectionElement(this.tokenProvider, this.SecurityMode, context, nameSettings, false);
                return;
            }

            case InternalConnectivityMode.Https:
            {
                this.connectionElement = new WebStreamRelayedConnectionElement(this.tokenProvider, this.SecurityMode, context, nameSettings, true);
                return;
            }

            case InternalConnectivityMode.HttpsWebSocket:
            {
                this.connectionElement = new WebSocketRelayedConnectionElement(this.tokenProvider, this.SecurityMode, context, nameSettings);
                return;
            }
            }
            throw new InvalidOperationException(SRClient.UnsupportedConnectivityMode(internalConnectivityMode));
        }
        public HybridConnectionListener(BindingContext context, TcpRelayTransportBindingElement transportBindingElement, int bufferSize, Uri uri, NameSettings nameSettings, TokenProvider tokenProvider)
        {
            this.bufferSize = bufferSize;
            IConnectionElement relayedSocketElement = new RelayedSocketElement(context, nameSettings, tokenProvider, SocketSecurityRole.None);
            DemuxSocketManager demuxSocketManager   = new DemuxSocketManager(relayedSocketElement, bufferSize, uri);
            IConnectionElement demuxSocketElement   = new DemuxSocketElement(relayedSocketElement, "relayed", demuxSocketManager);

            this.relayedSocketListener = demuxSocketElement.CreateListener(bufferSize, uri);
            this.relayedSocketAcceptor = new HybridConnectionListener.ConnectionAcceptor(this, this.relayedSocketListener, HybridConnectionListener.HybridConnectionSocketType.Relayed);
            IConnectionElement connectionElement = new DemuxSocketElement(relayedSocketElement, "direct", demuxSocketManager);
            Binding            binding           = HybridConnectionElement.CreateDirectControlBindingElement(context, transportBindingElement, connectionElement);

            this.directSocketListener = (new DirectSocketElement(binding)).CreateListener(bufferSize, uri);
            this.directSocketAcceptor = new HybridConnectionListener.ConnectionAcceptor(this, this.directSocketListener, HybridConnectionListener.HybridConnectionSocketType.Direct);
            this.connectionQueue      = new InputQueue <HybridConnection>();
            this.connectionTable      = new Dictionary <Guid, HybridConnection>();
        }