Esempio n. 1
0
        private IChannelFactory <IRequestSessionChannel> CreateChannelFactory(bool useSslStreamSecurity, bool includeExceptionDetails, DnsEndpointIdentity endpointIdentity)
        {
            string        str;
            int           num           = 0;
            CustomBinding customBinding = SbmpProtocolDefaults.CreateBinding(false, false, 2147483647, useSslStreamSecurity, endpointIdentity);
            DuplexRequestBindingElement duplexRequestBindingElement = new DuplexRequestBindingElement()
            {
                IncludeExceptionDetails = includeExceptionDetails,
                ClientMode = this.clientMode
            };
            DuplexRequestBindingElement duplexRequestBindingElement1 = duplexRequestBindingElement;
            int num1 = num;

            num = num1 + 1;
            customBinding.Elements.Insert(num1, duplexRequestBindingElement1);
            BindingParameterCollection bindingParameterCollection = new BindingParameterCollection();

            if (useSslStreamSecurity)
            {
                ClientCredentials clientCredential = new ClientCredentials();
                clientCredential.ServiceCertificate.Authentication.CertificateValidationMode  = X509CertificateValidationMode.Custom;
                clientCredential.ServiceCertificate.Authentication.CustomCertificateValidator = RetriableCertificateValidator.Instance;
                if (SoapProtocolDefaults.IsAvailableClientCertificateThumbprint(out str))
                {
                    clientCredential.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, str);
                }
                bindingParameterCollection.Add(clientCredential);
            }
            this.MessageVersion = customBinding.MessageVersion;
            return(customBinding.BuildChannelFactory <IRequestSessionChannel>(bindingParameterCollection));
        }
        private void Initialize(bool useWebStream, bool useHttpsWebStream, IEnumerable <Uri> baseAddresses)
        {
            List <Uri> uris = new List <Uri>();

            foreach (Uri baseAddress in baseAddresses)
            {
                if (base.Address == null)
                {
                    base.Address = baseAddress;
                }
                UriBuilder uriBuilder = new UriBuilder(baseAddress);
                if (!this.Settings.GatewayMode && string.Compare(uriBuilder.Scheme, "sb", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    ExceptionTrace exception        = Microsoft.ServiceBus.Messaging.FxTrace.Exception;
                    string         invalidUriScheme = Resources.InvalidUriScheme;
                    object[]       scheme           = new object[] { uriBuilder.Scheme, "sb" };
                    throw exception.AsError(new ArgumentException(Microsoft.ServiceBus.SR.GetString(invalidUriScheme, scheme)), null);
                }
                if (!useWebStream)
                {
                    uriBuilder.Scheme = SbmpProtocolDefaults.TransportUriScheme;
                }
                else
                {
                    uriBuilder.Scheme = "sb";
                    uriBuilder.Port   = (useHttpsWebStream ? RelayEnvironment.RelayHttpsPort : RelayEnvironment.RelayHttpPort);
                }
                if (!this.Settings.GatewayMode && uriBuilder.Port == -1)
                {
                    if (!useWebStream)
                    {
                        uriBuilder.Port = RelayEnvironment.RelayNmfPort;
                    }
                    else
                    {
                        uriBuilder.Port = (useHttpsWebStream ? RelayEnvironment.RelayHttpsPort : RelayEnvironment.RelayHttpPort);
                    }
                }
                MessagingUtilities.EnsureTrailingSlash(uriBuilder);
                uris.Add(uriBuilder.Uri);
            }
            this.baseAddresses = null;
            this.BaseAddress   = uris.First <Uri>();
            bool          useSslStreamSecurity = this.Settings.UseSslStreamSecurity;
            CustomBinding customBinding        = SbmpProtocolDefaults.CreateBinding(false, useWebStream, useHttpsWebStream, 2147483647, useSslStreamSecurity, this.Settings.EndpointIdentity);
            DuplexRequestBindingElement duplexRequestBindingElement = new DuplexRequestBindingElement()
            {
                ClientMode = !this.Settings.GatewayMode,
                IncludeExceptionDetails = true
            };
            DuplexRequestBindingElement duplexRequestBindingElement1 = duplexRequestBindingElement;
            int num = 0;

            if (!this.Settings.GatewayMode)
            {
                RedirectBindingElement redirectBindingElement = new RedirectBindingElement()
                {
                    EnableRedirect          = this.Settings.EnableRedirect,
                    UseSslStreamSecurity    = useSslStreamSecurity,
                    IncludeExceptionDetails = true,
                    EndpointIdentity        = this.Settings.EndpointIdentity
                };
                RedirectBindingElement redirectBindingElement1 = redirectBindingElement;
                int num1 = num;
                num = num1 + 1;
                customBinding.Elements.Insert(num1, new ReconnectBindingElement(uris));
                int num2 = num;
                num = num2 + 1;
                customBinding.Elements.Insert(num2, redirectBindingElement1);
            }
            int num3 = num;

            num = num3 + 1;
            customBinding.Elements.Insert(num3, new ReconnectBindingElement(uris));
            int num4 = num;

            num = num4 + 1;
            customBinding.Elements.Insert(num4, duplexRequestBindingElement1);
            BindingParameterCollection bindingParameterCollection = new BindingParameterCollection();

            if (useSslStreamSecurity)
            {
                ClientCredentials clientCredential = new ClientCredentials();
                clientCredential.ServiceCertificate.Authentication.CertificateValidationMode  = X509CertificateValidationMode.Custom;
                clientCredential.ServiceCertificate.Authentication.CustomCertificateValidator = RetriableCertificateValidator.Instance;
                bindingParameterCollection.Add(clientCredential);
            }
            this.ChannelFactory  = customBinding.BuildChannelFactory <IRequestSessionChannel>(bindingParameterCollection);
            this.MessageVersion  = customBinding.MessageVersion;
            this.ResourceManager = SbmpResourceManager.Instance;
            this.acceptMessageSessionForNamespaceLinkSettings = new CreateControlLinkSettings(this, string.Empty, "||", MessagingEntityType.Namespace, null);
            EventHandler eventHandler = new EventHandler(this.OnInnerFactoryFaulted);

            this.ChannelFactory.SafeAddFaulted(eventHandler);
        }
Esempio n. 3
0
 public static CustomBinding CreateBinding(bool portSharingEnabled, bool useWebStream, int maxReceivedMessageSize, bool useSslStreamSecurity, DnsEndpointIdentity endpointIdentity)
 {
     return(SbmpProtocolDefaults.CreateBinding(portSharingEnabled, useWebStream, false, maxReceivedMessageSize, useSslStreamSecurity, endpointIdentity));
 }