internal static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, PrivacyNoticeBindingElement privacy, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding) { WSFederationHttpSecurityMode mode; WSFederationHttpSecurity security2; bool isReliableSession = rsbe != null; binding = null; HttpTransportSecurity transportSecurity = new HttpTransportSecurity(); if (!GetSecurityModeFromTransport(transport, transportSecurity, out mode)) { return(false); } HttpsTransportBindingElement element = transport as HttpsTransportBindingElement; if (((element != null) && (element.MessageSecurityVersion != null)) && (element.MessageSecurityVersion.SecurityPolicyVersion != WSMessageSecurityVersion.SecurityPolicyVersion)) { return(false); } if (TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security2)) { binding = new WSFederationHttpBinding(security2, privacy, isReliableSession); } if ((rsbe != null) && (rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessagingFebruary2005)) { return(false); } if ((tfbe != null) && (tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransactionOctober2004)) { return(false); } return(binding != null); }
private static void GetWSFederationHttpBindingDetails(WSFederationHttpBinding binding, ref string name, ref string mode, ref string credentialType) { if (binding is WS2007FederationHttpBinding) { name = GetBindingName <WS2007FederationHttpBinding>(binding); } else { name = GetBindingName <WSFederationHttpBinding>(binding); } WSFederationHttpSecurity wSFederationHttpSecurity = binding.Security; mode = wSFederationHttpSecurity?.Mode.ToString(); switch (wSFederationHttpSecurity?.Mode) { case WSFederationHttpSecurityMode.None: credentialType = "N/A"; break; case WSFederationHttpSecurityMode.Message: case WSFederationHttpSecurityMode.TransportWithMessageCredential: credentialType = wSFederationHttpSecurity.Message?.IssuedTokenType ?? "null"; break; } }
[Category ("NotWorking")] // transport security public void DefaultValuesSecurityModeTransport () { WSFederationHttpBinding b = new WSFederationHttpBinding (WSFederationHttpSecurityMode.TransportWithMessageCredential); // common tests. DefaultValues (b, "https"); // WSFederationHttpSecurity WSFederationHttpSecurity sec = b.Security; Assert.IsNotNull (sec, "#2-1"); Assert.AreEqual (WSFederationHttpSecurityMode.TransportWithMessageCredential, sec.Mode, "#2-2"); // Security.Message FederatedMessageSecurityOverHttp msg = sec.Message; Assert.IsNotNull (msg, "#2-3"); Assert.AreEqual (SecurityAlgorithmSuite.Default, msg.AlgorithmSuite, "#2-3-2"); Assert.AreEqual (SecurityKeyType.SymmetricKey, msg.IssuedKeyType, "#2-3-3"); Assert.AreEqual (true, msg.NegotiateServiceCredential, "#2-3-4"); // Binding elements BindingElementCollection bec = b.CreateBindingElements (); Assert.AreEqual (4, bec.Count, "#5-1"); Assert.AreEqual (typeof (TransactionFlowBindingElement), bec [0].GetType (), "#5-2"); Assert.AreEqual (typeof (TransportSecurityBindingElement), bec [1].GetType (), "#5-3"); Assert.AreEqual (typeof (TextMessageEncodingBindingElement), bec [2].GetType (), "#5-4"); Assert.AreEqual (typeof (HttpsTransportBindingElement), bec [3].GetType (), "#5-5"); }
public static Binding CreateBinding(string bindingName) { Binding result = null; try { if (string.Compare(bindingName, typeof(WSHttpBinding).FullName, true) == 0) { result = new WSHttpBinding(); } else if (string.Compare(bindingName, typeof(WS2007HttpBinding).FullName, true) == 0) { result = new WS2007HttpBinding(); } else if (string.Compare(bindingName, typeof(BasicHttpBinding).FullName, true) == 0) { result = new BasicHttpBinding(); } else if (string.Compare(bindingName, typeof(WSDualHttpBinding).FullName, true) == 0) { result = new WSDualHttpBinding(); } else if (string.Compare(bindingName, typeof(WS2007FederationHttpBinding).FullName, true) == 0) { result = new WS2007FederationHttpBinding(); } else if (string.Compare(bindingName, typeof(WSFederationHttpBinding).FullName, true) == 0) { result = new WSFederationHttpBinding(); } else if (string.Compare(bindingName, typeof(NetNamedPipeBinding).FullName, true) == 0) { result = new NetNamedPipeBinding(); } else if (string.Compare(bindingName, typeof(NetMsmqBinding).FullName, true) == 0) { result = new NetMsmqBinding(); } else if (string.Compare(bindingName, typeof(MsmqIntegrationBinding).FullName, true) == 0) { result = new MsmqIntegrationBinding(); } else if (string.Compare(bindingName, typeof(NetTcpBinding).FullName, true) == 0) { result = new NetTcpBinding(); } else if (string.Compare(bindingName, typeof(NetPeerTcpBinding).FullName, true) == 0) { result = new NetPeerTcpBinding(); } } catch { result = new BasicHttpBinding(BasicHttpSecurityMode.None); } return result; }
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; }
private void SetSecuritySettings(Endpoint serviceInterface, WSFederationHttpBinding secureBinding) { GetStsSettingsFromEnvironment(serviceInterface); secureBinding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Basic256; secureBinding.Security.Message.NegotiateServiceCredential = false; secureBinding.Security.Message.EstablishSecurityContext = false; secureBinding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey; secureBinding.Security.Message.IssuedTokenType = null; var identity = EndpointIdentity.CreateDnsIdentity((new Uri(serviceInterface.IssuerName).DnsSafeHost)); secureBinding.Security.Message.IssuerAddress = CreateIssuerAddress(serviceInterface, identity); if (IsClient) secureBinding.Security.Message.IssuerBinding = CreateIssuerBinding(serviceInterface); else secureBinding.Security.Message.IssuerMetadataAddress = new EndpointAddress(new Uri(serviceInterface.IssuerMetadataAddress), identity); }
internal new static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, PrivacyNoticeBindingElement privacy, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding) { bool isReliableSession = (rsbe != null); binding = null; // reverse GetTransport HttpTransportSecurity transportSecurity = new HttpTransportSecurity(); WSFederationHttpSecurityMode mode; if (!WSFederationHttpBinding.GetSecurityModeFromTransport(transport, transportSecurity, out mode)) { return(false); } HttpsTransportBindingElement httpsBinding = transport as HttpsTransportBindingElement; if (httpsBinding != null && httpsBinding.MessageSecurityVersion != null) { if (httpsBinding.MessageSecurityVersion.SecurityPolicyVersion != s_WS2007MessageSecurityVersion.SecurityPolicyVersion) { return(false); } } WSFederationHttpSecurity security; if (WS2007FederationHttpBinding.TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security)) { binding = new WS2007FederationHttpBinding(security, privacy, isReliableSession); } if (rsbe != null && rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11) { return(false); } if (tfbe != null && tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransaction11) { return(false); } return(binding != null); }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 6) { return(false); } // collect all binding elements PrivacyNoticeBindingElement privacy = null; TransactionFlowBindingElement txFlow = null; ReliableSessionBindingElement session = null; SecurityBindingElement security = null; MessageEncodingBindingElement encoding = null; HttpTransportBindingElement transport = null; foreach (BindingElement element in elements) { if (element is SecurityBindingElement) { security = 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 PrivacyNoticeBindingElement) { privacy = element as PrivacyNoticeBindingElement; } else { return(false); } } if (transport == null) { return(false); } if (encoding == null) { return(false); } if (!transport.AuthenticationScheme.IsSingleton()) { //multiple authentication schemes selected -- not supported in StandardBindings return(false); } HttpsTransportBindingElement httpsTransport = transport as HttpsTransportBindingElement; if ((security != null) && (httpsTransport != null) && (httpsTransport.RequireClientCertificate != TransportDefaults.RequireClientCertificate)) { return(false); } if (null != privacy || !WSHttpBinding.TryCreate(security, transport, session, txFlow, out binding)) { if (!WSFederationHttpBinding.TryCreate(security, transport, privacy, session, txFlow, out binding)) { if (!WS2007HttpBinding.TryCreate(security, transport, session, txFlow, out binding)) { if (!WS2007FederationHttpBinding.TryCreate(security, transport, privacy, session, txFlow, out binding)) { return(false); } } } } if (txFlow == null) { txFlow = GetDefaultTransactionFlowBindingElement(); if ((binding is WS2007HttpBinding) || (binding is WS2007FederationHttpBinding)) { txFlow.TransactionProtocol = TransactionProtocol.WSAtomicTransaction11; } } WSHttpBindingBase wSHttpBindingBase = binding as WSHttpBindingBase; wSHttpBindingBase.InitializeFrom(transport, encoding, txFlow, session); if (!wSHttpBindingBase.IsBindingElementsMatch(transport, encoding, txFlow, session)) { return(false); } return(true); }
internal static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 6) { return(false); } PrivacyNoticeBindingElement privacy = null; System.ServiceModel.Channels.TransactionFlowBindingElement tfbe = null; System.ServiceModel.Channels.ReliableSessionBindingElement rsbe = null; SecurityBindingElement sbe = null; MessageEncodingBindingElement encoding = null; HttpTransportBindingElement transport = null; foreach (BindingElement element7 in elements) { if (element7 is SecurityBindingElement) { sbe = element7 as SecurityBindingElement; } else if (element7 is TransportBindingElement) { transport = element7 as HttpTransportBindingElement; } else if (element7 is MessageEncodingBindingElement) { encoding = element7 as MessageEncodingBindingElement; } else if (element7 is System.ServiceModel.Channels.TransactionFlowBindingElement) { tfbe = element7 as System.ServiceModel.Channels.TransactionFlowBindingElement; } else if (element7 is System.ServiceModel.Channels.ReliableSessionBindingElement) { rsbe = element7 as System.ServiceModel.Channels.ReliableSessionBindingElement; } else if (element7 is PrivacyNoticeBindingElement) { privacy = element7 as PrivacyNoticeBindingElement; } else { return(false); } } if (transport == null) { return(false); } if (encoding == null) { return(false); } if (((privacy != null) || !WSHttpBinding.TryCreate(sbe, transport, rsbe, tfbe, out binding)) && ((!WSFederationHttpBinding.TryCreate(sbe, transport, privacy, rsbe, tfbe, out binding) && !WS2007HttpBinding.TryCreate(sbe, transport, rsbe, tfbe, out binding)) && !WS2007FederationHttpBinding.TryCreate(sbe, transport, privacy, rsbe, tfbe, out binding))) { return(false); } if (tfbe == null) { tfbe = GetDefaultTransactionFlowBindingElement(); if ((binding is WS2007HttpBinding) || (binding is WS2007FederationHttpBinding)) { tfbe.TransactionProtocol = TransactionProtocol.WSAtomicTransaction11; } } WSHttpBindingBase base2 = binding as WSHttpBindingBase; base2.InitializeFrom(transport, encoding, tfbe, rsbe); if (!base2.IsBindingElementsMatch(transport, encoding, tfbe, rsbe)) { return(false); } return(true); }
/// <summary> /// 绑定的协议 /// </summary> /// <param name="strBindingName">strBindingName</param> /// <returns>Binding</returns> public static Binding WCfBindingName(string strBindingName) { switch (strBindingName.ToUpper()) { case "WSHTTPBINDING": WSHttpBinding wsbinding = new WSHttpBinding(); wsbinding.MaxReceivedMessageSize = 4048000; wsbinding.MaxBufferPoolSize = 1048576; wsbinding.ReaderQuotas.MaxStringContentLength = 4048000; wsbinding.ReaderQuotas.MaxArrayLength = 4048000; wsbinding.ReaderQuotas.MaxBytesPerRead = 4048000; wsbinding.SendTimeout = new TimeSpan(0, 3, 0); return wsbinding; case "WSDUALHTTPBINDING": WSDualHttpBinding wsdbinding = new WSDualHttpBinding(); wsdbinding.MaxReceivedMessageSize = 4048000; wsdbinding.MaxBufferPoolSize = 1048576; wsdbinding.ReaderQuotas.MaxStringContentLength = 4048000; wsdbinding.ReaderQuotas.MaxArrayLength = 4048000; wsdbinding.ReaderQuotas.MaxBytesPerRead = 4048000; wsdbinding.SendTimeout = new TimeSpan(0, 3, 0); return wsdbinding; case "WSFEDERATIONHTTPBINDING": WSFederationHttpBinding wsfe = new WSFederationHttpBinding(); wsfe.MaxReceivedMessageSize = 4048000; wsfe.MaxBufferPoolSize = 1048576; wsfe.ReaderQuotas.MaxStringContentLength = 4048000; wsfe.ReaderQuotas.MaxArrayLength = 4048000; wsfe.ReaderQuotas.MaxBytesPerRead = 4048000; wsfe.SendTimeout = new TimeSpan(0, 3, 0); return wsfe; case "NETTCPBINDING": NetTcpBinding netTcpBinding = new NetTcpBinding(); netTcpBinding.MaxReceivedMessageSize = 4048000; netTcpBinding.MaxBufferPoolSize = 1048576; netTcpBinding.ReaderQuotas.MaxStringContentLength = 4048000; return netTcpBinding; case "NETNAMEDPIPEBINDING": NetNamedPipeBinding netNamePipeBinding = new NetNamedPipeBinding(); netNamePipeBinding.MaxReceivedMessageSize = 4048000; netNamePipeBinding.MaxBufferPoolSize = 1048576; netNamePipeBinding.ReaderQuotas.MaxStringContentLength = 4048000; return netNamePipeBinding; case "NETMSMQBINDING": return new NetMsmqBinding(); case "NETPEERTCPBINDING": return new NetPeerTcpBinding(); case "CUSTOMBINDING": BinaryMessageEncodingBindingElement encodingBindingElement = new BinaryMessageEncodingBindingElement(); encodingBindingElement.ReaderQuotas.MaxStringContentLength = 4048000; HttpTransportBindingElement transportBindingElement = new HttpTransportBindingElement(); transportBindingElement.MaxReceivedMessageSize = 4048000; transportBindingElement.MaxBufferSize = 4048000; transportBindingElement.MaxBufferPoolSize = 4048000; CustomBinding customBinding = new CustomBinding(encodingBindingElement, transportBindingElement); customBinding.SendTimeout = new TimeSpan(0, 3, 0); return customBinding; default: BasicHttpBinding binding = new BasicHttpBinding(); binding.MaxReceivedMessageSize = 4048000; binding.MaxBufferSize = 4048000; binding.MaxBufferPoolSize = 1048576; binding.ReaderQuotas.MaxStringContentLength = 4048000; binding.ReaderQuotas.MaxArrayLength = 4048000; binding.ReaderQuotas.MaxBytesPerRead = 4048000; binding.SendTimeout = new TimeSpan(0, 3, 0); return binding; } }
/// <summary> /// /// </summary> /// <param name="bindingType"></param> /// <param name="setting"></param> /// <returns></returns> public Binding CreateBinding(BindingType bindingType, BindingBehaviorSetting setting) { Binding bindinginstance = null; switch (bindingType) { case BindingType.BasicHttpBinding: BasicHttpBinding basicHttp = new BasicHttpBinding(); basicHttp.MaxReceivedMessageSize = MaxReceivedSize; bindinginstance = basicHttp; break; case BindingType.NetNamedPipeBinding: NetNamedPipeBinding wsPipe = new NetNamedPipeBinding(); wsPipe.MaxReceivedMessageSize = MaxReceivedSize; bindinginstance = wsPipe; break; case BindingType.NetPeerTcpBinding: NetPeerTcpBinding wsPeerTcp = new NetPeerTcpBinding(); wsPeerTcp.MaxReceivedMessageSize = MaxReceivedSize; bindinginstance = wsPeerTcp; break; case BindingType.NetTcpBinding: NetTcpBinding wsTcp = new NetTcpBinding(); wsTcp.MaxReceivedMessageSize = MaxReceivedSize; wsTcp.ReliableSession.Enabled = true; wsTcp.ReliableSession.InactivityTimeout = setting.InactivityTimeout; wsTcp.Security.Mode = SecurityMode.None; wsTcp.OpenTimeout = setting.ConnectTimeout; wsTcp.CloseTimeout = setting.ConnectTimeout; wsTcp.SendTimeout = setting.SendTimeout; wsTcp.ReceiveTimeout = setting.ReceiveTimeout; bindinginstance = wsTcp; break; case BindingType.WsDualHttpBinding: WSDualHttpBinding wsDual = new WSDualHttpBinding(); wsDual.MaxReceivedMessageSize = MaxReceivedSize; bindinginstance = wsDual; break; case BindingType.WsFederationHttpBinding: WSFederationHttpBinding wsFederation = new WSFederationHttpBinding(); wsFederation.MaxReceivedMessageSize = MaxReceivedSize; bindinginstance = wsFederation; break; case BindingType.WsHttpBinding: WSHttpBinding wsHttp = new WSHttpBinding(SecurityMode.None); wsHttp.MaxReceivedMessageSize = MaxReceivedSize; wsHttp.Security.Message.ClientCredentialType = MessageCredentialType.Windows; wsHttp.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; bindinginstance = wsHttp; break; default: throw new ArgumentOutOfRangeException("bindingType"); } return bindinginstance; }
void DefaultValues (WSFederationHttpBinding b, string scheme) { Assert.AreEqual (false, b.BypassProxyOnLocal, "#1"); Assert.AreEqual (HostNameComparisonMode.StrongWildcard, b.HostNameComparisonMode, "#2"); Assert.AreEqual (0x80000, b.MaxBufferPoolSize, "#3"); Assert.AreEqual (0x10000, b.MaxReceivedMessageSize, "#5"); Assert.AreEqual (WSMessageEncoding.Text, b.MessageEncoding, "#6"); Assert.IsNull (b.ProxyAddress, "#7"); // FIXME: test b.ReaderQuotas Assert.AreEqual (scheme, b.Scheme, "#8"); Assert.AreEqual (EnvelopeVersion.Soap12, b.EnvelopeVersion, "#9"); Assert.AreEqual (65001, b.TextEncoding.CodePage, "#10"); // utf-8 Assert.AreEqual (false, b.TransactionFlow, "#11"); Assert.AreEqual (true, b.UseDefaultWebProxy, "#12"); Assert.AreEqual (MessageVersion.Default, b.MessageVersion, "#14"); Assert.IsNotNull (b.ReliableSession, "#15"); }
// if you make changes here, see also WS2007FederationHttpBinding.TryCreate() internal static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, PrivacyNoticeBindingElement privacy, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding) { bool isReliableSession = (rsbe != null); binding = null; // reverse GetTransport HttpTransportSecurity transportSecurity = new HttpTransportSecurity(); WSFederationHttpSecurityMode mode; if (!GetSecurityModeFromTransport(transport, transportSecurity, out mode)) { return false; } HttpsTransportBindingElement httpsBinding = transport as HttpsTransportBindingElement; if (httpsBinding != null && httpsBinding.MessageSecurityVersion != null) { if (httpsBinding.MessageSecurityVersion.SecurityPolicyVersion != WSMessageSecurityVersion.SecurityPolicyVersion) { return false; } } WSFederationHttpSecurity security; if (TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security)) { binding = new WSFederationHttpBinding(security, privacy, isReliableSession); } if (rsbe != null && rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessagingFebruary2005) { return false; } if (tfbe != null && tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransactionOctober2004) { return false; } return binding != null; }
internal static bool TryCreate(SecurityBindingElement sbe, TransportBindingElement transport, PrivacyNoticeBindingElement privacy, ReliableSessionBindingElement rsbe, TransactionFlowBindingElement tfbe, out Binding binding) { WSFederationHttpSecurityMode mode; WSFederationHttpSecurity security2; bool isReliableSession = rsbe != null; binding = null; HttpTransportSecurity transportSecurity = new HttpTransportSecurity(); if (!GetSecurityModeFromTransport(transport, transportSecurity, out mode)) { return false; } HttpsTransportBindingElement element = transport as HttpsTransportBindingElement; if (((element != null) && (element.MessageSecurityVersion != null)) && (element.MessageSecurityVersion.SecurityPolicyVersion != WSMessageSecurityVersion.SecurityPolicyVersion)) { return false; } if (TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security2)) { binding = new WSFederationHttpBinding(security2, privacy, isReliableSession); } if ((rsbe != null) && (rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessagingFebruary2005)) { return false; } if ((tfbe != null) && (tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransactionOctober2004)) { return false; } return (binding != null); }