private bool PrepareElements() { if (elements != empty_collection) { return(false); } elements = binding.CreateBindingElements(); return(true); }
public void CtorFromAnotherBinding () { CustomBinding cb = new CustomBinding (new WSHttpBinding ()); // Its properties become mostly copy of the original one Assert.AreEqual (4, cb.Elements.Count, "#1"); Assert.AreEqual ("http", cb.Scheme, "#2"); Assert.AreEqual ("WSHttpBinding", cb.Name, "#3"); Assert.AreEqual ("http://tempuri.org/", cb.Namespace, "#4"); Assert.AreEqual (4, cb.CreateBindingElements ().Count, "#9"); }
public void DefaultCtor () { CustomBinding cb = new CustomBinding (); Assert.AreEqual (0, cb.Elements.Count, "#1"); Assert.AreEqual ("CustomBinding", cb.Name, "#3"); Assert.AreEqual ("http://tempuri.org/", cb.Namespace, "#4"); Assert.AreEqual (TimeSpan.FromMinutes (1), cb.OpenTimeout, "#5"); Assert.AreEqual (TimeSpan.FromMinutes (1), cb.CloseTimeout, "#6"); Assert.AreEqual (TimeSpan.FromMinutes (1), cb.SendTimeout, "#7"); Assert.AreEqual (TimeSpan.FromMinutes (10), cb.ReceiveTimeout, "#8"); Assert.AreEqual (0, cb.CreateBindingElements ().Count, "#9"); }
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; } } }
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; } } }