Пример #1
0
        public static Binding GetWsHttpContextBinding()
        {
            WSHttpContextBinding binding = new WSHttpContextBinding();

            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            binding.ReaderQuotas.MaxBytesPerRead        = int.MaxValue;
            binding.CloseTimeout           = TimeSpan.FromMinutes(1);
            binding.OpenTimeout            = TimeSpan.FromMinutes(1);
            binding.ReceiveTimeout         = TimeSpan.FromSeconds(ResourceManagementClient.Configuration.ReceiveTimeoutSeconds);
            binding.SendTimeout            = TimeSpan.FromSeconds(ResourceManagementClient.Configuration.SendTimeoutSeconds);
            binding.BypassProxyOnLocal     = false;
            binding.TransactionFlow        = false;
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
            binding.Security.Transport.ProxyCredentialType  = HttpProxyCredentialType.None;
            binding.Security.Message.ClientCredentialType   = MessageCredentialType.Windows;

            binding.Security.Message.EstablishSecurityContext   = false;
            binding.Security.Message.NegotiateServiceCredential = true;

            return(binding);
        }
Пример #2
0
 public void Main()
 {
     WSHttpContextBinding serviceMultipleTokenBinding = new WSHttpContextBinding()
     {
         MaxBufferPoolSize      = 2.M(),  // instead of 2097152
         MaxReceivedMessageSize = 64.K(), // instead of 65536
     };
 }
        protected override void OnApplyConfiguration(Binding binding)
        {
            base.OnApplyConfiguration(binding);
            WSHttpContextBinding contextBinding = (WSHttpContextBinding)binding;

            contextBinding.ClientCallbackAddress    = this.ClientCallbackAddress;
            contextBinding.ContextProtectionLevel   = this.ContextProtectionLevel;
            contextBinding.ContextManagementEnabled = this.ContextManagementEnabled;
        }
        protected internal override void InitializeFrom(Binding binding)
        {
            base.InitializeFrom(binding);
            WSHttpContextBinding contextBinding = (WSHttpContextBinding)binding;

            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ClientCallbackAddressName, contextBinding.ClientCallbackAddress);
            SetPropertyValueIfNotDefaultValue(WSHttpContextBindingElement.ContextManagementEnabledName, contextBinding.ContextManagementEnabled);
            SetPropertyValueIfNotDefaultValue(WSHttpContextBindingElement.ContextProtectionLevelName, contextBinding.ContextProtectionLevel);
        }
Пример #5
0
        public static Binding WcfBindingFactory(string bindingtype, string bidingconfigname)
        {
            Binding binding = null;

            if (!string.IsNullOrEmpty(bindingtype) && !string.IsNullOrEmpty(bidingconfigname))
            {
                switch (bindingtype)
                {
                case "basicHttpBinding":
                    binding = new BasicHttpBinding(bidingconfigname);
                    break;

                case "basicHttpContextBinding":
                    binding = new BasicHttpContextBinding(bidingconfigname);
                    break;

                case "wsHttpBinding":
                    binding = new WSHttpBinding(bidingconfigname);
                    break;

                case "wsHttpContextBinding":
                    binding = new WSHttpContextBinding(bidingconfigname);
                    break;

                case "netTcpBinding":
                    binding = new NetTcpBinding(bidingconfigname);
                    break;

                case "netTcpContextBinding":
                    binding = new NetTcpContextBinding(bidingconfigname);
                    break;

                case "netPeerTcpBinding":
                    binding = new NetPeerTcpBinding(bidingconfigname);
                    break;

                case "netNamedPipeBinding":
                    binding = new NetNamedPipeBinding(bidingconfigname);
                    break;

                case "webHttpBinding":
                    binding = new WSHttpBinding(bidingconfigname);
                    break;

                case "wsDualHttpBinding":
                    binding = new WSDualHttpBinding(bidingconfigname);
                    break;

                case "customBinding":
                    binding = new CustomBinding(bidingconfigname);
                    break;
                }
            }

            return(binding);
        }
        protected internal override void InitializeFrom(Binding binding)
        {
            base.InitializeFrom(binding);
            WSHttpContextBinding binding2 = (WSHttpContextBinding)binding;

            this.ClientCallbackAddress = binding2.ClientCallbackAddress;
            if (!binding2.ContextManagementEnabled)
            {
                this.ContextManagementEnabled = binding2.ContextManagementEnabled;
            }
            this.ContextProtectionLevel = binding2.ContextProtectionLevel;
        }
        public override BindingElementCollection CreateBindingElements()
        {
            WSHttpContextBinding binding = new WSHttpContextBinding();

            binding.Security.Message.EstablishSecurityContext   = false;
            binding.Security.Message.NegotiateServiceCredential = true;

            BindingElementCollection bindingElements = binding.CreateBindingElements();

            bindingElements.Find <SecurityBindingElement>().OptionalEndpointSupportingTokenParameters.Endorsing.Add(
                new CustomSecurityTokenParameters());
            return(bindingElements);
        }
Пример #8
0
        public static WSHttpContextBinding ServiceMultipleTokenBinding_Common(TimeSpan?receiveTimeout = null, int?maxReceivedMessageSize = null)
        {
            var binding = new WSHttpContextBinding(SecurityMode.Message)
            {
                ReceiveTimeout         = receiveTimeout ?? new TimeSpan(0, 10, 0),
                MaxReceivedMessageSize = maxReceivedMessageSize ?? 2048576
            };

            binding.Security.Message.AlgorithmSuite           = SecurityAlgorithmSuite.Default;
            binding.Security.Message.EstablishSecurityContext = false;

            return(binding);
        }
Пример #9
0
        private static Binding GetWSHttpContextBinding()
        {
            var binding = new WSHttpContextBinding();

            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.Security.Mode          = SecurityMode.None;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
            binding.ReaderQuotas.MaxDepth = int.MaxValue;
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            binding.ReaderQuotas.MaxArrayLength         = int.MaxValue;
            binding.ReaderQuotas.MaxBytesPerRead        = int.MaxValue;
            binding.ReaderQuotas.MaxNameTableCharCount  = int.MaxValue;
            return(binding);
        }
        public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (context.Endpoint == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint");
            }
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }

            // Try to post-process the unrecognized RequireHttpCookie assertion to augment the AllowCookies value
            // of HttpTransportBindingElement

            CustomBinding customBinding = context.Endpoint.Binding as CustomBinding;

            if (customBinding != null)
            {
                UnrecognizedAssertionsBindingElement unrecognized = null;
                unrecognized = customBinding.Elements.Find <UnrecognizedAssertionsBindingElement>();
                HttpTransportBindingElement http = null;
                if (unrecognized != null)
                {
                    XmlElement httpUseCookieAssertion = null;
                    if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(unrecognized.BindingAsserions, out httpUseCookieAssertion))
                    {
                        foreach (BindingElement element in customBinding.Elements)
                        {
                            http = element as HttpTransportBindingElement;
                            if (http != null)
                            {
                                http.AllowCookies = true;
                                unrecognized.BindingAsserions.Remove(httpUseCookieAssertion);
                                if (unrecognized.BindingAsserions.Count == 0)
                                {
                                    customBinding.Elements.Remove(unrecognized);
                                }
                                break;
                            }
                        }
                    }
                }

                // Try to upgrade to standard binding

                BindingElementCollection bindingElements = customBinding.CreateBindingElements();
                Binding binding;
                if (!WSHttpContextBinding.TryCreate(bindingElements, out binding) &&
                    !NetTcpContextBinding.TryCreate(bindingElements, out binding))
                {
                    // Work around BasicHttpBinding.TryCreate insensitivity to HttpTransportBindingElement.AllowCookies value

                    if (http == null)
                    {
                        foreach (BindingElement bindingElement in bindingElements)
                        {
                            http = bindingElement as HttpTransportBindingElement;
                            if (http != null)
                            {
                                break;
                            }
                        }
                    }
                    if (http != null && http.AllowCookies)
                    {
                        http.AllowCookies = false;
                        if (BasicHttpBinding.TryCreate(bindingElements, out binding))
                        {
                            ((BasicHttpBinding)binding).AllowCookies = true;
                        }
                    }
                }

                if (binding != null)
                {
                    binding.Name             = context.Endpoint.Binding.Name;
                    binding.Namespace        = context.Endpoint.Binding.Namespace;
                    context.Endpoint.Binding = binding;
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Get a binding based on values of this class
        /// </summary>
        /// <returns>Hydrated binding</returns>
        /// <exception cref="InvalidOperationException">Thrown if requested binding doesn't match one of the implemented bindings</exception>
        public Binding GetBinding()
        {
            System.ServiceModel.Channels.Binding binder = null;
            switch (this.Binding)
            {
            case WcfBindings.BasicHttp:
                if (!string.IsNullOrWhiteSpace(ConfigurationName))
                {
                    binder = new BasicHttpBinding(ConfigurationName);
                }
                else
                {
                    binder = new BasicHttpBinding()
                    {
                        BypassProxyOnLocal     = ByPassProxyOnLocal,
                        MaxBufferPoolSize      = MaxBufferSize,
                        MaxReceivedMessageSize = MaxReceivedMessageSize,
                        //UseDefaultWebProxy = UseDefaultProxy,
                        ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
                        {
                            MaxArrayLength         = MaxArrayLength,
                            MaxBytesPerRead        = MaxBytesPerRead,
                            MaxDepth               = MaxDepth,
                            MaxNameTableCharCount  = MaxNameTableCharCount,
                            MaxStringContentLength = MaxStringContentLength
                        }
                    };
                }
                break;

            case WcfBindings.BasicContext:
                if (!string.IsNullOrWhiteSpace(ConfigurationName))
                {
                    binder = new BasicHttpContextBinding(ConfigurationName);
                }
                else
                {
                    binder = new BasicHttpContextBinding()
                    {
                        BypassProxyOnLocal     = ByPassProxyOnLocal,
                        MaxBufferPoolSize      = MaxBufferSize,
                        MaxReceivedMessageSize = MaxReceivedMessageSize,
                        UseDefaultWebProxy     = UseDefaultProxy,
                        ProxyAddress           = new Uri(ProxyAddress),
                        ReaderQuotas           = new System.Xml.XmlDictionaryReaderQuotas()
                        {
                            MaxArrayLength         = MaxArrayLength,
                            MaxBytesPerRead        = MaxBytesPerRead,
                            MaxDepth               = MaxDepth,
                            MaxNameTableCharCount  = MaxNameTableCharCount,
                            MaxStringContentLength = MaxStringContentLength
                        }
                    };
                }
                break;

            case WcfBindings.NetTcp:
                if (!string.IsNullOrWhiteSpace(ConfigurationName))
                {
                    binder = new NetTcpBinding(ConfigurationName);
                }
                else
                {
                    binder = new NetTcpBinding()
                    {
                        MaxBufferPoolSize      = MaxBufferSize,
                        MaxReceivedMessageSize = MaxReceivedMessageSize,
                        ReaderQuotas           = new System.Xml.XmlDictionaryReaderQuotas()
                        {
                            MaxArrayLength         = MaxArrayLength,
                            MaxBytesPerRead        = MaxBytesPerRead,
                            MaxDepth               = MaxDepth,
                            MaxNameTableCharCount  = MaxNameTableCharCount,
                            MaxStringContentLength = MaxStringContentLength
                        }
                    };
                }
                break;

            case WcfBindings.WebHttp:
                if (!string.IsNullOrWhiteSpace(ConfigurationName))
                {
                    binder = new WebHttpBinding(ConfigurationName);
                }
                else
                {
                    binder = new WebHttpBinding()
                    {
                        BypassProxyOnLocal     = ByPassProxyOnLocal,
                        MaxBufferPoolSize      = MaxBufferSize,
                        MaxReceivedMessageSize = MaxReceivedMessageSize,
                        UseDefaultWebProxy     = UseDefaultProxy,
                        ProxyAddress           = new Uri(ProxyAddress),
                        ReaderQuotas           = new System.Xml.XmlDictionaryReaderQuotas()
                        {
                            MaxArrayLength         = MaxArrayLength,
                            MaxBytesPerRead        = MaxBytesPerRead,
                            MaxDepth               = MaxDepth,
                            MaxNameTableCharCount  = MaxNameTableCharCount,
                            MaxStringContentLength = MaxStringContentLength
                        }
                    };
                }
                break;

            case WcfBindings.WsHttpBinding:
                if (!string.IsNullOrWhiteSpace(ConfigurationName))
                {
                    binder = new WSHttpBinding(ConfigurationName);
                }
                else
                {
                    binder = new WSHttpBinding()
                    {
                        BypassProxyOnLocal     = ByPassProxyOnLocal,
                        MaxBufferPoolSize      = MaxBufferSize,
                        MaxReceivedMessageSize = MaxReceivedMessageSize,
                        UseDefaultWebProxy     = UseDefaultProxy,
                        ProxyAddress           = new Uri(ProxyAddress),
                        ReaderQuotas           = new System.Xml.XmlDictionaryReaderQuotas()
                        {
                            MaxArrayLength         = MaxArrayLength,
                            MaxBytesPerRead        = MaxBytesPerRead,
                            MaxDepth               = MaxDepth,
                            MaxNameTableCharCount  = MaxNameTableCharCount,
                            MaxStringContentLength = MaxStringContentLength
                        }
                    };
                }
                break;

            case WcfBindings.WsHttpContext:
                if (!string.IsNullOrWhiteSpace(ConfigurationName))
                {
                    binder = new WSHttpContextBinding(ConfigurationName);
                }
                else
                {
                    binder = new WSHttpContextBinding()
                    {
                        BypassProxyOnLocal     = ByPassProxyOnLocal,
                        MaxBufferPoolSize      = MaxBufferSize,
                        MaxReceivedMessageSize = MaxReceivedMessageSize,
                        UseDefaultWebProxy     = UseDefaultProxy,
                        ProxyAddress           = new Uri(ProxyAddress),
                        ReaderQuotas           = new System.Xml.XmlDictionaryReaderQuotas()
                        {
                            MaxArrayLength         = MaxArrayLength,
                            MaxBytesPerRead        = MaxBytesPerRead,
                            MaxDepth               = MaxDepth,
                            MaxNameTableCharCount  = MaxNameTableCharCount,
                            MaxStringContentLength = MaxStringContentLength
                        }
                    };
                }
                break;

            default:
                throw ExceptionFactory.New <InvalidOperationException>("Unable to instantiante a binding of '{0}'", this.Binding.ToString());
            }

            binder.CloseTimeout   = CloseTimeout;
            binder.OpenTimeout    = OpenTimeout;
            binder.ReceiveTimeout = ReceiveTimeout;
            binder.SendTimeout    = SendTimeout;
            return(binder);
        }
        public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (context.Endpoint == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint");
            }
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }
            CustomBinding binding = context.Endpoint.Binding as CustomBinding;

            if (binding != null)
            {
                System.ServiceModel.Channels.Binding binding2;
                UnrecognizedAssertionsBindingElement item = null;
                item = binding.Elements.Find <UnrecognizedAssertionsBindingElement>();
                HttpTransportBindingElement element2 = null;
                if (item != null)
                {
                    XmlElement httpUseCookieAssertion = null;
                    if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(item.BindingAsserions, out httpUseCookieAssertion))
                    {
                        foreach (BindingElement element4 in binding.Elements)
                        {
                            element2 = element4 as HttpTransportBindingElement;
                            if (element2 != null)
                            {
                                element2.AllowCookies = true;
                                item.BindingAsserions.Remove(httpUseCookieAssertion);
                                if (item.BindingAsserions.Count == 0)
                                {
                                    binding.Elements.Remove(item);
                                }
                                break;
                            }
                        }
                    }
                }
                BindingElementCollection bindingElements = binding.CreateBindingElements();
                if (!WSHttpContextBinding.TryCreate(bindingElements, out binding2) && !NetTcpContextBinding.TryCreate(bindingElements, out binding2))
                {
                    if (element2 == null)
                    {
                        foreach (BindingElement element5 in bindingElements)
                        {
                            element2 = element5 as HttpTransportBindingElement;
                            if (element2 != null)
                            {
                                break;
                            }
                        }
                    }
                    if ((element2 != null) && element2.AllowCookies)
                    {
                        element2.AllowCookies = false;
                        if (BasicHttpBinding.TryCreate(bindingElements, out binding2))
                        {
                            ((BasicHttpBinding)binding2).AllowCookies = true;
                        }
                    }
                }
                if (binding2 != null)
                {
                    binding2.Name            = context.Endpoint.Binding.Name;
                    binding2.Namespace       = context.Endpoint.Binding.Namespace;
                    context.Endpoint.Binding = binding2;
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Creates the appropriate binding type for the given element
        /// </summary>
        /// <param name="endPoint">Enpoint to create binding object for</param>
        /// <returns>Binding represented in the config file</returns>
        private static Binding GetBinding(ChannelEndpointElement endPoint)
        {
            Binding binding = null;

            try
            {
                switch (endPoint.Binding)
                {
                case "basicHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new BasicHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new BasicHttpBinding();
                    }
                    break;

                case "basicHttpContextBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new BasicHttpContextBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new BasicHttpContextBinding();
                    }
                    break;

                case "customBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new CustomBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new CustomBinding();
                    }
                    break;

                case "netNamedPipeBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetNamedPipeBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetNamedPipeBinding();
                    }
                    break;

                case "netPeerTcpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetPeerTcpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetPeerTcpBinding();
                    }
                    break;

                case "netTcpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetTcpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetTcpBinding();
                    }
                    break;

                case "netTcpContextBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetTcpContextBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetTcpContextBinding();
                    }
                    break;

                case "webHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WebHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WebHttpBinding();
                    }
                    break;

                case "ws2007HttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WS2007HttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WS2007HttpBinding();
                    }
                    break;

                case "wsHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WSHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WSHttpBinding();
                    }
                    break;

                case "wsHttpContextBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WSHttpContextBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WSHttpContextBinding();
                    }
                    break;

                case "wsDualHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WSDualHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WSDualHttpBinding();
                    }
                    break;

                case "wsFederationHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WSFederationHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WSFederationHttpBinding();
                    }
                    break;

                case "ws2007FederationHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WS2007FederationHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WS2007FederationHttpBinding();
                    }
                    break;

                case "msmqIntegrationBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new MsmqIntegrationBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new MsmqIntegrationBinding();
                    }
                    break;

                case "netMsmqBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetMsmqBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetMsmqBinding();
                    }
                    break;

                case "netHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetHttpBinding();
                    }
                    break;

                case "netHttpsBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetHttpsBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetHttpBinding();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "." + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw ex;
            }

            return(binding);
        }