internal static new bool TryCreate(BindingElementCollection bindingElements, out Binding binding)
        {
            if (bindingElements == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingElements");
            }

            binding = null;

            ContextBindingElement contextBindingElement = bindingElements.Find <ContextBindingElement>();

            if (contextBindingElement != null)
            {
                BindingElementCollection bindingElementsWithoutContext = new BindingElementCollection(bindingElements);
                bindingElementsWithoutContext.Remove <ContextBindingElement>();
                Binding wsHttpBinding;
                if (WSHttpBinding.TryCreate(bindingElementsWithoutContext, out wsHttpBinding))
                {
                    bool allowCookies = ((WSHttpBinding)wsHttpBinding).AllowCookies;
                    if (allowCookies && contextBindingElement.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie ||
                        !allowCookies && contextBindingElement.ContextExchangeMechanism == ContextExchangeMechanism.ContextSoapHeader)
                    {
                        WSHttpContextBinding contextBinding = new WSHttpContextBinding((WSHttpBinding)wsHttpBinding);
                        contextBinding.ContextProtectionLevel   = contextBindingElement.ProtectionLevel;
                        contextBinding.ContextManagementEnabled = contextBindingElement.ContextManagementEnabled;
                        binding = contextBinding;
                    }
                }
            }

            return(binding != null);
        }
Ejemplo n.º 2
0
        internal static bool TryCreate(BindingElementCollection bindingElements, out Binding binding)
        {
            if (bindingElements == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingElements");
            }
            binding = null;
            ContextBindingElement element = bindingElements.Find <ContextBindingElement>();

            if (element != null)
            {
                Binding binding2;
                BindingElementCollection elements = new BindingElementCollection(bindingElements);
                elements.Remove <ContextBindingElement>();
                if (WSHttpBindingBase.TryCreate(elements, out binding2))
                {
                    bool allowCookies = ((WSHttpBinding)binding2).AllowCookies;
                    if ((allowCookies && (element.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)) || (!allowCookies && (element.ContextExchangeMechanism == ContextExchangeMechanism.ContextSoapHeader)))
                    {
                        WSHttpContextBinding binding3 = new WSHttpContextBinding((WSHttpBinding)binding2)
                        {
                            ContextProtectionLevel   = element.ProtectionLevel,
                            ContextManagementEnabled = element.ContextManagementEnabled
                        };
                        binding = binding3;
                    }
                }
            }
            return(binding != null);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
 public static Binding Resolve(WcfBindingTypes type)
 {
     Binding binding = null;
     switch (type)
     {
         case WcfBindingTypes.BasicHttpBinding:
             binding = new BasicHttpBinding();
             break;
         case WcfBindingTypes.NetTcpBinding:
             binding = new NetTcpBinding();
             break;
         case WcfBindingTypes.NetTcpContextBinding:
             binding = new NetTcpContextBinding();
             break;
         case WcfBindingTypes.WsHttpBinding:
             binding = new WSHttpBinding();
             break;
         case WcfBindingTypes.NetMsmqBinding:
             binding = new NetMsmqBinding();
             break;
         case WcfBindingTypes.NetPeerTcpBinding:
             binding = new NetPeerTcpBinding();
             break;
         case WcfBindingTypes.BasicHttpContextBinding:
             binding = new BasicHttpContextBinding();
             break;
         case WcfBindingTypes.WSHttpContextBinding:
             binding = new WSHttpContextBinding();
             break;
         case WcfBindingTypes.WS2007FederationHttpBinding:
             binding = new WS2007FederationHttpBinding();
             break;
         case WcfBindingTypes.WS2007HttpBinding:
             binding = new WS2007HttpBinding();
             break;
         case WcfBindingTypes.NetNamedPipeBinding:
             binding = new NetNamedPipeBinding();
             break;
         case WcfBindingTypes.WSFederationHttpBinding:
             binding = new WSFederationHttpBinding();
             break;
         case WcfBindingTypes.WSDualHttpBinding:
             binding = new WSDualHttpBinding();
             break;
         default:
             binding = new CustomBinding();
             break;
     }
     return binding;
 }
        internal static new bool TryCreate(BindingElementCollection bindingElements, out Binding binding)
        {
            if (bindingElements == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingElements");
            }

            binding = null;

            ContextBindingElement contextBindingElement = bindingElements.Find<ContextBindingElement>();
            if (contextBindingElement != null)
            {
                BindingElementCollection bindingElementsWithoutContext = new BindingElementCollection(bindingElements);
                bindingElementsWithoutContext.Remove<ContextBindingElement>();
                Binding wsHttpBinding;
                if (WSHttpBinding.TryCreate(bindingElementsWithoutContext, out wsHttpBinding))
                {
                    bool allowCookies = ((WSHttpBinding)wsHttpBinding).AllowCookies;
                    if (allowCookies && contextBindingElement.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie
                        || !allowCookies && contextBindingElement.ContextExchangeMechanism == ContextExchangeMechanism.ContextSoapHeader)
                    {
                        WSHttpContextBinding contextBinding = new WSHttpContextBinding((WSHttpBinding)wsHttpBinding);
                        contextBinding.ContextProtectionLevel = contextBindingElement.ProtectionLevel;
                        contextBinding.ContextManagementEnabled = contextBindingElement.ContextManagementEnabled;
                        binding = contextBinding;
                    }
                }
            }

            return binding != null;
        }
        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;
        }
 internal static bool TryCreate(BindingElementCollection bindingElements, out Binding binding)
 {
     if (bindingElements == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bindingElements");
     }
     binding = null;
     ContextBindingElement element = bindingElements.Find<ContextBindingElement>();
     if (element != null)
     {
         Binding binding2;
         BindingElementCollection elements = new BindingElementCollection(bindingElements);
         elements.Remove<ContextBindingElement>();
         if (WSHttpBindingBase.TryCreate(elements, out binding2))
         {
             bool allowCookies = ((WSHttpBinding) binding2).AllowCookies;
             if ((allowCookies && (element.ContextExchangeMechanism == ContextExchangeMechanism.HttpCookie)) || (!allowCookies && (element.ContextExchangeMechanism == ContextExchangeMechanism.ContextSoapHeader)))
             {
                 WSHttpContextBinding binding3 = new WSHttpContextBinding((WSHttpBinding) binding2) {
                     ContextProtectionLevel = element.ProtectionLevel,
                     ContextManagementEnabled = element.ContextManagementEnabled
                 };
                 binding = binding3;
             }
         }
     }
     return (binding != null);
 }
Ejemplo n.º 8
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;
		}