internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 7) { return(false); } SecurityBindingElement sbe = null; HttpTransportBindingElement transport = null; MessageEncodingBindingElement encoding = null; TransactionFlowBindingElement txFlow = null; ReliableSessionBindingElement session = null; CompositeDuplexBindingElement compositeDuplex = null; OneWayBindingElement oneWay = null; foreach (BindingElement element in elements) { if (element is SecurityBindingElement) { sbe = element as SecurityBindingElement; } else if (element is TransportBindingElement) { transport = element as HttpTransportBindingElement; } else if (element is MessageEncodingBindingElement) { encoding = element as MessageEncodingBindingElement; } else if (element is TransactionFlowBindingElement) { txFlow = element as TransactionFlowBindingElement; } else if (element is ReliableSessionBindingElement) { session = element as ReliableSessionBindingElement; } else if (element is CompositeDuplexBindingElement) { compositeDuplex = element as CompositeDuplexBindingElement; } else if (element is OneWayBindingElement) { oneWay = element as OneWayBindingElement; } else { return(false); } } if (transport == null) { return(false); } if (encoding == null) { return(false); } // this binding only supports Soap12 if (!encoding.CheckEncodingVersion(EnvelopeVersion.Soap12)) { return(false); } if (compositeDuplex == null) { return(false); } if (oneWay == null) { return(false); } if (session == null) { return(false); } if (txFlow == null) { txFlow = GetDefaultTransactionFlowBindingElement(); } WSDualHttpSecurity security; if (!TryCreateSecurity(sbe, out security)) { return(false); } WSDualHttpBinding wSDualHttpBinding = new WSDualHttpBinding(transport, encoding, txFlow, session, compositeDuplex, oneWay, security); if (!wSDualHttpBinding.IsBindingElementsMatch(transport, encoding, txFlow, session, compositeDuplex, oneWay)) { return(false); } binding = wSDualHttpBinding; return(true); }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 3) { return(false); } SecurityBindingElement securityElement = null; MessageEncodingBindingElement encoding = null; HttpTransportBindingElement transport = null; foreach (BindingElement element in elements) { if (element is SecurityBindingElement) { securityElement = element as SecurityBindingElement; } else if (element is TransportBindingElement) { transport = element as HttpTransportBindingElement; } else if (element is MessageEncodingBindingElement) { encoding = element as MessageEncodingBindingElement; } else { return(false); } } HttpsTransportBindingElement httpsTransport = transport as HttpsTransportBindingElement; if ((securityElement != null) && (httpsTransport != null) && (httpsTransport.RequireClientCertificate != TransportDefaults.RequireClientCertificate)) { return(false); } // process transport binding element UnifiedSecurityMode mode; HttpTransportSecurity transportSecurity = new HttpTransportSecurity(); if (!GetSecurityModeFromTransport(transport, transportSecurity, out mode)) { return(false); } if (encoding == null) { return(false); } // BasicHttpBinding only supports Soap11 if (!encoding.CheckEncodingVersion(EnvelopeVersion.Soap11)) { return(false); } BasicHttpSecurity security; if (!HttpBindingBase.TryCreateSecurity(securityElement, mode, transportSecurity, out security)) { return(false); } BasicHttpBinding basicHttpBinding = new BasicHttpBinding(security); basicHttpBinding.InitializeFrom(transport, encoding); // make sure all our defaults match if (!basicHttpBinding.IsBindingElementsMatch(transport, encoding)) { return(false); } binding = basicHttpBinding; return(true); }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { UnifiedSecurityMode mode; BasicHttpSecurity security2; binding = null; if (elements.Count > 3) { return(false); } SecurityBindingElement securityElement = null; MessageEncodingBindingElement encoding = null; HttpTransportBindingElement http = null; foreach (BindingElement element4 in elements) { if (element4 is SecurityBindingElement) { securityElement = element4 as SecurityBindingElement; } else if (element4 is TransportBindingElement) { http = element4 as HttpTransportBindingElement; } else if (element4 is MessageEncodingBindingElement) { encoding = element4 as MessageEncodingBindingElement; } else { return(false); } } HttpTransportSecurity transportSecurity = new HttpTransportSecurity(); if (!GetSecurityModeFromTransport(http, transportSecurity, out mode)) { return(false); } if (encoding == null) { return(false); } if (!encoding.CheckEncodingVersion(System.ServiceModel.EnvelopeVersion.Soap11)) { return(false); } if (!TryCreateSecurity(securityElement, mode, transportSecurity, out security2)) { return(false); } BasicHttpBinding binding2 = new BasicHttpBinding(security2); binding2.InitializeFrom(http, encoding); if (!binding2.IsBindingElementsMatch(http, encoding)) { return(false); } binding = binding2; return(true); }