void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
 {
     if (policyContext == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext");
     }
     XmlElement element = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), "PrivacyNotice", "http://schemas.xmlsoap.org/ws/2005/05/identity", true);
     if (element != null)
     {
         PrivacyNoticeBindingElement item = policyContext.BindingElements.Find<PrivacyNoticeBindingElement>();
         if (item == null)
         {
             item = new PrivacyNoticeBindingElement();
             policyContext.BindingElements.Add(item);
         }
         item.Url = new Uri(element.InnerText);
         string attribute = element.GetAttribute("Version", "http://schemas.xmlsoap.org/ws/2005/05/identity");
         if (string.IsNullOrEmpty(attribute))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CannotImportPrivacyNoticeElementWithoutVersionAttribute")));
         }
         int result = 0;
         if (!int.TryParse(attribute, out result))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("PrivacyNoticeElementVersionAttributeInvalid")));
         }
         item.Version = result;
     }
 }
 WS2007FederationHttpBinding(WSFederationHttpSecurity security, PrivacyNoticeBindingElement privacy, bool reliableSessionEnabled)
     : base(security, privacy, reliableSessionEnabled)
 {
     this.ReliableSessionBindingElement.ReliableMessagingVersion = WS2007ReliableMessagingVersion;
     this.TransactionFlowBindingElement.TransactionProtocol = WS2007TransactionProtocol;
     this.HttpsTransport.MessageSecurityVersion = WS2007MessageSecurityVersion;
 }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext)
        {
            if (policyContext == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("policyContext");

            XmlElement privacyNoticeAssertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(),
                PrivacyNoticePolicyStrings.PrivacyNoticeName, PrivacyNoticePolicyStrings.PrivacyNoticeNamespace, true);
            if (privacyNoticeAssertion != null)
            {
                PrivacyNoticeBindingElement settings =
                    policyContext.BindingElements.Find<PrivacyNoticeBindingElement>();

                if (null == settings)
                {
                    settings = new PrivacyNoticeBindingElement();
                    policyContext.BindingElements.Add(settings);
                }

                settings.Url = new Uri(privacyNoticeAssertion.InnerText);
                string versionString = privacyNoticeAssertion.GetAttribute(PrivacyNoticePolicyStrings.PrivacyNoticeVersionAttributeName, PrivacyNoticePolicyStrings.PrivacyNoticeNamespace);
                if (string.IsNullOrEmpty(versionString))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotImportPrivacyNoticeElementWithoutVersionAttribute)));
                }

                int version = 0;
                if (!Int32.TryParse(versionString, out version))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.PrivacyNoticeElementVersionAttributeInvalid)));
                }
                settings.Version = version;
            }
        }
 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 (!WSFederationHttpBinding.GetSecurityModeFromTransport(transport, transportSecurity, out mode))
     {
         return false;
     }
     HttpsTransportBindingElement element = transport as HttpsTransportBindingElement;
     if (((element != null) && (element.MessageSecurityVersion != null)) && (element.MessageSecurityVersion.SecurityPolicyVersion != WS2007MessageSecurityVersion.SecurityPolicyVersion))
     {
         return false;
     }
     if (TryCreateSecurity(sbe, mode, transportSecurity, isReliableSession, out security2))
     {
         binding = new WS2007FederationHttpBinding(security2, privacy, isReliableSession);
     }
     if ((rsbe != null) && (rsbe.ReliableMessagingVersion != ReliableMessagingVersion.WSReliableMessaging11))
     {
         return false;
     }
     if ((tfbe != null) && (tfbe.TransactionProtocol != TransactionProtocol.WSAtomicTransaction11))
     {
         return false;
     }
     return (binding != null);
 }
        protected internal override BindingElement CreateBindingElement()
        {
            PrivacyNoticeBindingElement bindingElement = new PrivacyNoticeBindingElement();

            this.ApplyConfiguration(bindingElement);
            return(bindingElement);
        }
 private WS2007FederationHttpBinding(WSFederationHttpSecurity security, PrivacyNoticeBindingElement privacy, bool reliableSessionEnabled)
     : base(security, privacy, reliableSessionEnabled)
 {
     this.ReliableSessionBindingElement.ReliableMessagingVersion = s_WS2007ReliableMessagingVersion;
     this.TransactionFlowBindingElement.TransactionProtocol      = s_WS2007TransactionProtocol;
     this.HttpsTransport.MessageSecurityVersion = s_WS2007MessageSecurityVersion;
 }
Beispiel #7
0
        protected internal override void InitializeFrom(BindingElement bindingElement)
        {
            base.InitializeFrom(bindingElement);
            PrivacyNoticeBindingElement binding = (PrivacyNoticeBindingElement)bindingElement;

            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Url, binding.Url);
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Version, binding.Version);
        }
        public override void ApplyConfiguration(BindingElement bindingElement)
        {
            base.ApplyConfiguration(bindingElement);
            PrivacyNoticeBindingElement element = (PrivacyNoticeBindingElement)bindingElement;

            element.Url     = this.Url;
            element.Version = this.Version;
        }
        protected internal override void InitializeFrom(BindingElement bindingElement)
        {
            base.InitializeFrom(bindingElement);
            PrivacyNoticeBindingElement element = (PrivacyNoticeBindingElement)bindingElement;

            this.Url     = element.Url;
            this.Version = element.Version;
        }
Beispiel #10
0
 internal WSFederationHttpBinding(WSFederationHttpSecurity security, PrivacyNoticeBindingElement privacy, bool reliableSessionEnabled)
     : base(reliableSessionEnabled)
 {
     _security = security;
     if (null != privacy)
     {
         _privacyNoticeAt      = privacy.Url;
         _privacyNoticeVersion = privacy.Version;
     }
 }
 internal WSFederationHttpBinding(WSFederationHttpSecurity security, PrivacyNoticeBindingElement privacy, bool reliableSessionEnabled)
     : base(reliableSessionEnabled)
 {
     this.security = security;
     if (null != privacy)
     {
         this.privacyNoticeAt = privacy.Url;
         this.privacyNoticeVersion = privacy.Version;
     }
 }
 internal WSFederationHttpBinding(WSFederationHttpSecurity security, PrivacyNoticeBindingElement privacy, bool reliableSessionEnabled) : base(reliableSessionEnabled)
 {
     this.security = new WSFederationHttpSecurity();
     this.security = security;
     if (privacy != null)
     {
         this.privacyNoticeAt      = privacy.Url;
         this.privacyNoticeVersion = privacy.Version;
     }
 }
        public override BindingElementCollection CreateBindingElements()
        {
            BindingElementCollection    elements = base.CreateBindingElements();
            PrivacyNoticeBindingElement item     = this.CreatePrivacyPolicy();

            if (item != null)
            {
                elements.Insert(0, item);
            }
            return(elements);
        }
 private PrivacyNoticeBindingElement CreatePrivacyPolicy()
 {
     PrivacyNoticeBindingElement element = null;
     if (this.PrivacyNoticeAt != null)
     {
         element = new PrivacyNoticeBindingElement {
             Url = this.PrivacyNoticeAt,
             Version = this.privacyNoticeVersion
         };
     }
     return element;
 }
        private PrivacyNoticeBindingElement CreatePrivacyPolicy()
        {
            PrivacyNoticeBindingElement element = null;

            if (this.PrivacyNoticeAt != null)
            {
                element = new PrivacyNoticeBindingElement {
                    Url     = this.PrivacyNoticeAt,
                    Version = this.privacyNoticeVersion
                };
            }
            return(element);
        }
Beispiel #16
0
        private PrivacyNoticeBindingElement CreatePrivacyPolicy()
        {
            PrivacyNoticeBindingElement privacy = null;

            if (this.PrivacyNoticeAt != null)
            {
                privacy         = new PrivacyNoticeBindingElement();
                privacy.Url     = this.PrivacyNoticeAt;
                privacy.Version = _privacyNoticeVersion;
            }

            return(privacy);
        }
 private static void GetPrivacyNoticeLinkFromIssuerBinding(Binding issuerBinding, out Uri privacyNotice, out int privacyNoticeVersion)
 {
     privacyNotice        = null;
     privacyNoticeVersion = 0;
     if (issuerBinding != null)
     {
         PrivacyNoticeBindingElement element = issuerBinding.CreateBindingElements().Find <PrivacyNoticeBindingElement>();
         if (element != null)
         {
             privacyNotice        = element.Url;
             privacyNoticeVersion = element.Version;
         }
     }
 }
Beispiel #18
0
        public override BindingElementCollection CreateBindingElements()
        {   // return collection of BindingElements
            BindingElementCollection bindingElements = base.CreateBindingElements();
            // order of BindingElements is important

            PrivacyNoticeBindingElement privacy = this.CreatePrivacyPolicy();

            if (privacy != null)
            {
                // This must go first.
                bindingElements.Insert(0, privacy);
            }

            return(bindingElements);
        }
Beispiel #19
0
        //
        // Summary:
        // Given an issuer Binding retrieves any privacy notice links that might be present.
        //
        static void GetPrivacyNoticeLinkFromIssuerBinding(Binding issuerBinding, out Uri privacyNotice, out int privacyNoticeVersion)
        {
            privacyNotice        = null;
            privacyNoticeVersion = 0;

            if (null != issuerBinding)
            {
                PrivacyNoticeBindingElement privacyNoticeBE =
                    issuerBinding.CreateBindingElements().Find <PrivacyNoticeBindingElement>();

                if (null != privacyNoticeBE)
                {
                    privacyNotice        = privacyNoticeBE.Url;
                    privacyNoticeVersion = privacyNoticeBE.Version;
                }
            }
        }
        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 != 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;
        }
        PrivacyNoticeBindingElement CreatePrivacyPolicy()
        {
            PrivacyNoticeBindingElement privacy = null;

            if (this.PrivacyNoticeAt != null)
            {
                privacy = new PrivacyNoticeBindingElement();
                privacy.Url = this.PrivacyNoticeAt;
                privacy.Version = this.privacyNoticeVersion;
            }

            return privacy;
        }
 private static void FillBindingInfo(BindingElement bindingElement, ref IWmiInstance instance)
 {
     if (bindingElement is IWmiInstanceProvider)
     {
         IWmiInstanceProvider provider = (IWmiInstanceProvider)bindingElement;
         instance = instance.NewInstance(provider.GetInstanceType());
         provider.FillInstance(instance);
     }
     else
     {
         System.Type serviceModelBaseType = AdministrationHelpers.GetServiceModelBaseType(bindingElement.GetType());
         if (null != serviceModelBaseType)
         {
             instance = instance.NewInstance(serviceModelBaseType.Name);
             if (bindingElement is TransportBindingElement)
             {
                 TransportBindingElement element = (TransportBindingElement)bindingElement;
                 instance.SetProperty("ManualAddressing", element.ManualAddressing);
                 instance.SetProperty("MaxReceivedMessageSize", element.MaxReceivedMessageSize);
                 instance.SetProperty("MaxBufferPoolSize", element.MaxBufferPoolSize);
                 instance.SetProperty("Scheme", element.Scheme);
                 if (bindingElement is ConnectionOrientedTransportBindingElement)
                 {
                     ConnectionOrientedTransportBindingElement element2 = (ConnectionOrientedTransportBindingElement)bindingElement;
                     instance.SetProperty("ConnectionBufferSize", element2.ConnectionBufferSize);
                     instance.SetProperty("HostNameComparisonMode", element2.HostNameComparisonMode.ToString());
                     instance.SetProperty("ChannelInitializationTimeout", element2.ChannelInitializationTimeout);
                     instance.SetProperty("MaxBufferSize", element2.MaxBufferSize);
                     instance.SetProperty("MaxPendingConnections", element2.MaxPendingConnections);
                     instance.SetProperty("MaxOutputDelay", element2.MaxOutputDelay);
                     instance.SetProperty("MaxPendingAccepts", element2.MaxPendingAccepts);
                     instance.SetProperty("TransferMode", element2.TransferMode.ToString());
                     if (bindingElement is TcpTransportBindingElement)
                     {
                         TcpTransportBindingElement element3 = (TcpTransportBindingElement)bindingElement;
                         instance.SetProperty("ListenBacklog", element3.ListenBacklog);
                         instance.SetProperty("PortSharingEnabled", element3.PortSharingEnabled);
                         instance.SetProperty("TeredoEnabled", element3.TeredoEnabled);
                         IWmiInstance instance2 = instance.NewInstance("TcpConnectionPoolSettings");
                         instance2.SetProperty("GroupName", element3.ConnectionPoolSettings.GroupName);
                         instance2.SetProperty("IdleTimeout", element3.ConnectionPoolSettings.IdleTimeout);
                         instance2.SetProperty("LeaseTimeout", element3.ConnectionPoolSettings.LeaseTimeout);
                         instance2.SetProperty("MaxOutboundConnectionsPerEndpoint", element3.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint);
                         instance.SetProperty("ConnectionPoolSettings", instance2);
                         FillExtendedProtectionPolicy(instance, element3.ExtendedProtectionPolicy);
                     }
                     else if (bindingElement is NamedPipeTransportBindingElement)
                     {
                         NamedPipeTransportBindingElement element4 = (NamedPipeTransportBindingElement)bindingElement;
                         IWmiInstance instance3 = instance.NewInstance("NamedPipeConnectionPoolSettings");
                         instance3.SetProperty("GroupName", element4.ConnectionPoolSettings.GroupName);
                         instance3.SetProperty("IdleTimeout", element4.ConnectionPoolSettings.IdleTimeout);
                         instance3.SetProperty("MaxOutboundConnectionsPerEndpoint", element4.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint);
                         instance.SetProperty("ConnectionPoolSettings", instance3);
                     }
                 }
                 else if (!(bindingElement is HttpTransportBindingElement))
                 {
                     if (!(bindingElement is MsmqBindingElementBase))
                     {
                         if (bindingElement is PeerTransportBindingElement)
                         {
                             PeerTransportBindingElement element9 = (PeerTransportBindingElement)bindingElement;
                             instance.SetProperty("ListenIPAddress", element9.ListenIPAddress);
                             instance.SetProperty("Port", element9.Port);
                             IWmiInstance instance4 = instance.NewInstance("PeerSecuritySettings");
                             instance4.SetProperty("Mode", element9.Security.Mode.ToString());
                             IWmiInstance instance5 = instance4.NewInstance("PeerTransportSecuritySettings");
                             instance5.SetProperty("CredentialType", element9.Security.Transport.CredentialType.ToString());
                             instance4.SetProperty("Transport", instance5);
                             instance.SetProperty("Security", instance4);
                         }
                     }
                     else
                     {
                         MsmqBindingElementBase base2 = (MsmqBindingElementBase)bindingElement;
                         if (null != base2.CustomDeadLetterQueue)
                         {
                             instance.SetProperty("CustomDeadLetterQueue", base2.CustomDeadLetterQueue.AbsoluteUri.ToString());
                         }
                         instance.SetProperty("DeadLetterQueue", base2.DeadLetterQueue);
                         instance.SetProperty("Durable", base2.Durable);
                         instance.SetProperty("ExactlyOnce", base2.ExactlyOnce);
                         instance.SetProperty("MaxRetryCycles", base2.MaxRetryCycles);
                         instance.SetProperty("ReceiveContextEnabled", base2.ReceiveContextEnabled);
                         instance.SetProperty("ReceiveErrorHandling", base2.ReceiveErrorHandling);
                         instance.SetProperty("ReceiveRetryCount", base2.ReceiveRetryCount);
                         instance.SetProperty("RetryCycleDelay", base2.RetryCycleDelay);
                         instance.SetProperty("TimeToLive", base2.TimeToLive);
                         instance.SetProperty("UseSourceJournal", base2.UseSourceJournal);
                         instance.SetProperty("UseMsmqTracing", base2.UseMsmqTracing);
                         instance.SetProperty("ValidityDuration", base2.ValidityDuration);
                         MsmqTransportBindingElement element7 = base2 as MsmqTransportBindingElement;
                         if (element7 != null)
                         {
                             instance.SetProperty("MaxPoolSize", element7.MaxPoolSize);
                             instance.SetProperty("QueueTransferProtocol", element7.QueueTransferProtocol);
                             instance.SetProperty("UseActiveDirectory", element7.UseActiveDirectory);
                         }
                         MsmqIntegrationBindingElement element8 = base2 as MsmqIntegrationBindingElement;
                         if (element8 != null)
                         {
                             instance.SetProperty("SerializationFormat", element8.SerializationFormat.ToString());
                         }
                     }
                 }
                 else
                 {
                     HttpTransportBindingElement element5 = (HttpTransportBindingElement)bindingElement;
                     instance.SetProperty("AllowCookies", element5.AllowCookies);
                     instance.SetProperty("AuthenticationScheme", element5.AuthenticationScheme.ToString());
                     instance.SetProperty("BypassProxyOnLocal", element5.BypassProxyOnLocal);
                     instance.SetProperty("DecompressionEnabled", element5.DecompressionEnabled);
                     instance.SetProperty("HostNameComparisonMode", element5.HostNameComparisonMode.ToString());
                     instance.SetProperty("KeepAliveEnabled", element5.KeepAliveEnabled);
                     instance.SetProperty("MaxBufferSize", element5.MaxBufferSize);
                     if (null != element5.ProxyAddress)
                     {
                         instance.SetProperty("ProxyAddress", element5.ProxyAddress.AbsoluteUri.ToString());
                     }
                     instance.SetProperty("ProxyAuthenticationScheme", element5.ProxyAuthenticationScheme.ToString());
                     instance.SetProperty("Realm", element5.Realm);
                     instance.SetProperty("TransferMode", element5.TransferMode.ToString());
                     instance.SetProperty("UnsafeConnectionNtlmAuthentication", element5.UnsafeConnectionNtlmAuthentication);
                     instance.SetProperty("UseDefaultWebProxy", element5.UseDefaultWebProxy);
                     FillExtendedProtectionPolicy(instance, element5.ExtendedProtectionPolicy);
                     if (bindingElement is HttpsTransportBindingElement)
                     {
                         HttpsTransportBindingElement element6 = (HttpsTransportBindingElement)bindingElement;
                         instance.SetProperty("RequireClientCertificate", element6.RequireClientCertificate);
                     }
                 }
             }
             else if (bindingElement is PeerResolverBindingElement)
             {
                 PeerResolverBindingElement element10 = (PeerResolverBindingElement)bindingElement;
                 instance.SetProperty("ReferralPolicy", element10.ReferralPolicy.ToString());
                 if (bindingElement is PeerCustomResolverBindingElement)
                 {
                     PeerCustomResolverBindingElement element11 = (PeerCustomResolverBindingElement)bindingElement;
                     if (element11.Address != null)
                     {
                         instance.SetProperty("Address", element11.Address.ToString());
                     }
                     if (element11.Binding != null)
                     {
                         instance.SetProperty("Binding", element11.Binding.ToString());
                     }
                 }
             }
             else if (bindingElement is ReliableSessionBindingElement)
             {
                 ReliableSessionBindingElement element12 = (ReliableSessionBindingElement)bindingElement;
                 instance.SetProperty("AcknowledgementInterval", element12.AcknowledgementInterval);
                 instance.SetProperty("FlowControlEnabled", element12.FlowControlEnabled);
                 instance.SetProperty("InactivityTimeout", element12.InactivityTimeout);
                 instance.SetProperty("MaxPendingChannels", element12.MaxPendingChannels);
                 instance.SetProperty("MaxRetryCount", element12.MaxRetryCount);
                 instance.SetProperty("MaxTransferWindowSize", element12.MaxTransferWindowSize);
                 instance.SetProperty("Ordered", element12.Ordered);
                 instance.SetProperty("ReliableMessagingVersion", element12.ReliableMessagingVersion.ToString());
             }
             else if (bindingElement is SecurityBindingElement)
             {
                 SecurityBindingElement element13 = (SecurityBindingElement)bindingElement;
                 instance.SetProperty("AllowInsecureTransport", element13.AllowInsecureTransport);
                 instance.SetProperty("DefaultAlgorithmSuite", element13.DefaultAlgorithmSuite.ToString());
                 instance.SetProperty("EnableUnsecuredResponse", element13.EnableUnsecuredResponse);
                 instance.SetProperty("IncludeTimestamp", element13.IncludeTimestamp);
                 instance.SetProperty("KeyEntropyMode", element13.KeyEntropyMode.ToString());
                 instance.SetProperty("SecurityHeaderLayout", element13.SecurityHeaderLayout.ToString());
                 instance.SetProperty("MessageSecurityVersion", element13.MessageSecurityVersion.ToString());
                 IWmiInstance instance6 = instance.NewInstance("LocalServiceSecuritySettings");
                 instance6.SetProperty("DetectReplays", element13.LocalServiceSettings.DetectReplays);
                 instance6.SetProperty("InactivityTimeout", element13.LocalServiceSettings.InactivityTimeout);
                 instance6.SetProperty("IssuedCookieLifetime", element13.LocalServiceSettings.IssuedCookieLifetime);
                 instance6.SetProperty("MaxCachedCookies", element13.LocalServiceSettings.MaxCachedCookies);
                 instance6.SetProperty("MaxClockSkew", element13.LocalServiceSettings.MaxClockSkew);
                 instance6.SetProperty("MaxPendingSessions", element13.LocalServiceSettings.MaxPendingSessions);
                 instance6.SetProperty("MaxStatefulNegotiations", element13.LocalServiceSettings.MaxStatefulNegotiations);
                 instance6.SetProperty("NegotiationTimeout", element13.LocalServiceSettings.NegotiationTimeout);
                 instance6.SetProperty("ReconnectTransportOnFailure", element13.LocalServiceSettings.ReconnectTransportOnFailure);
                 instance6.SetProperty("ReplayCacheSize", element13.LocalServiceSettings.ReplayCacheSize);
                 instance6.SetProperty("ReplayWindow", element13.LocalServiceSettings.ReplayWindow);
                 instance6.SetProperty("SessionKeyRenewalInterval", element13.LocalServiceSettings.SessionKeyRenewalInterval);
                 instance6.SetProperty("SessionKeyRolloverInterval", element13.LocalServiceSettings.SessionKeyRolloverInterval);
                 instance6.SetProperty("TimestampValidityDuration", element13.LocalServiceSettings.TimestampValidityDuration);
                 instance.SetProperty("LocalServiceSecuritySettings", instance6);
                 if (bindingElement is AsymmetricSecurityBindingElement)
                 {
                     AsymmetricSecurityBindingElement element14 = (AsymmetricSecurityBindingElement)bindingElement;
                     instance.SetProperty("MessageProtectionOrder", element14.MessageProtectionOrder.ToString());
                     instance.SetProperty("RequireSignatureConfirmation", element14.RequireSignatureConfirmation);
                 }
                 else if (bindingElement is SymmetricSecurityBindingElement)
                 {
                     SymmetricSecurityBindingElement element15 = (SymmetricSecurityBindingElement)bindingElement;
                     instance.SetProperty("MessageProtectionOrder", element15.MessageProtectionOrder.ToString());
                     instance.SetProperty("RequireSignatureConfirmation", element15.RequireSignatureConfirmation);
                 }
             }
             else if (bindingElement is WindowsStreamSecurityBindingElement)
             {
                 WindowsStreamSecurityBindingElement element16 = (WindowsStreamSecurityBindingElement)bindingElement;
                 instance.SetProperty("ProtectionLevel", element16.ProtectionLevel.ToString());
             }
             else if (bindingElement is SslStreamSecurityBindingElement)
             {
                 SslStreamSecurityBindingElement element17 = (SslStreamSecurityBindingElement)bindingElement;
                 instance.SetProperty("RequireClientCertificate", element17.RequireClientCertificate);
             }
             else if (bindingElement is CompositeDuplexBindingElement)
             {
                 CompositeDuplexBindingElement element18 = (CompositeDuplexBindingElement)bindingElement;
                 if (element18.ClientBaseAddress != null)
                 {
                     instance.SetProperty("ClientBaseAddress", element18.ClientBaseAddress.AbsoluteUri);
                 }
             }
             else if (bindingElement is OneWayBindingElement)
             {
                 OneWayBindingElement element19 = (OneWayBindingElement)bindingElement;
                 IWmiInstance         instance7 = instance.NewInstance("ChannelPoolSettings");
                 instance7.SetProperty("IdleTimeout", element19.ChannelPoolSettings.IdleTimeout);
                 instance7.SetProperty("LeaseTimeout", element19.ChannelPoolSettings.LeaseTimeout);
                 instance7.SetProperty("MaxOutboundChannelsPerEndpoint", element19.ChannelPoolSettings.MaxOutboundChannelsPerEndpoint);
                 instance.SetProperty("ChannelPoolSettings", instance7);
                 instance.SetProperty("PacketRoutable", element19.PacketRoutable);
                 instance.SetProperty("MaxAcceptedChannels", element19.MaxAcceptedChannels);
             }
             else if (bindingElement is MessageEncodingBindingElement)
             {
                 MessageEncodingBindingElement element20 = (MessageEncodingBindingElement)bindingElement;
                 instance.SetProperty("MessageVersion", element20.MessageVersion.ToString());
                 if (bindingElement is BinaryMessageEncodingBindingElement)
                 {
                     BinaryMessageEncodingBindingElement element21 = (BinaryMessageEncodingBindingElement)bindingElement;
                     instance.SetProperty("MaxSessionSize", element21.MaxSessionSize);
                     instance.SetProperty("MaxReadPoolSize", element21.MaxReadPoolSize);
                     instance.SetProperty("MaxWritePoolSize", element21.MaxWritePoolSize);
                     if (element21.ReaderQuotas != null)
                     {
                         FillReaderQuotas(instance, element21.ReaderQuotas);
                     }
                 }
                 else if (!(bindingElement is TextMessageEncodingBindingElement))
                 {
                     if (bindingElement is MtomMessageEncodingBindingElement)
                     {
                         MtomMessageEncodingBindingElement element23 = (MtomMessageEncodingBindingElement)bindingElement;
                         instance.SetProperty("Encoding", element23.WriteEncoding.WebName);
                         instance.SetProperty("MessageVersion", element23.MessageVersion.ToString());
                         instance.SetProperty("MaxReadPoolSize", element23.MaxReadPoolSize);
                         instance.SetProperty("MaxWritePoolSize", element23.MaxWritePoolSize);
                         if (element23.ReaderQuotas != null)
                         {
                             FillReaderQuotas(instance, element23.ReaderQuotas);
                         }
                     }
                 }
                 else
                 {
                     TextMessageEncodingBindingElement element22 = (TextMessageEncodingBindingElement)bindingElement;
                     instance.SetProperty("Encoding", element22.WriteEncoding.WebName);
                     instance.SetProperty("MaxReadPoolSize", element22.MaxReadPoolSize);
                     instance.SetProperty("MaxWritePoolSize", element22.MaxWritePoolSize);
                     if (element22.ReaderQuotas != null)
                     {
                         FillReaderQuotas(instance, element22.ReaderQuotas);
                     }
                 }
             }
             else if (bindingElement is TransactionFlowBindingElement)
             {
                 TransactionFlowBindingElement element24 = (TransactionFlowBindingElement)bindingElement;
                 instance.SetProperty("TransactionFlow", element24.Transactions);
                 instance.SetProperty("TransactionProtocol", element24.TransactionProtocol.ToString());
                 instance.SetProperty("AllowWildcardAction", element24.AllowWildcardAction);
             }
             else if (bindingElement is PrivacyNoticeBindingElement)
             {
                 PrivacyNoticeBindingElement element25 = (PrivacyNoticeBindingElement)bindingElement;
                 instance.SetProperty("Url", element25.Url.ToString());
                 instance.SetProperty("PrivacyNoticeVersion", element25.Version);
             }
         }
     }
 }
Beispiel #23
0
        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);
        }
Beispiel #24
0
        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);
        }
        static void FillBindingInfo(BindingElement bindingElement, ref IWmiInstance instance)
        {
            Fx.Assert(null != bindingElement, "");
            Fx.Assert(null != instance, "");

            if (bindingElement is IWmiInstanceProvider)
            {
                IWmiInstanceProvider instanceProvider = (IWmiInstanceProvider)bindingElement;
                instance = instance.NewInstance(instanceProvider.GetInstanceType());
                instanceProvider.FillInstance(instance);
                return;
            }

            Type elementType = AdministrationHelpers.GetServiceModelBaseType(bindingElement.GetType());

            if (null != elementType)
            {
                instance = instance.NewInstance(elementType.Name);
                if (bindingElement is TransportBindingElement)
                {
                    TransportBindingElement transport = (TransportBindingElement)bindingElement;
                    instance.SetProperty(AdministrationStrings.ManualAddressing, transport.ManualAddressing);
                    instance.SetProperty(AdministrationStrings.MaxReceivedMessageSize, transport.MaxReceivedMessageSize);
                    instance.SetProperty(AdministrationStrings.MaxBufferPoolSize, transport.MaxBufferPoolSize);
                    instance.SetProperty(AdministrationStrings.Scheme, transport.Scheme);

                    if (bindingElement is ConnectionOrientedTransportBindingElement)
                    {
                        ConnectionOrientedTransportBindingElement connectionOriented = (ConnectionOrientedTransportBindingElement)bindingElement;
                        instance.SetProperty(AdministrationStrings.ConnectionBufferSize, connectionOriented.ConnectionBufferSize);
                        instance.SetProperty(AdministrationStrings.HostNameComparisonMode, connectionOriented.HostNameComparisonMode.ToString());
                        instance.SetProperty(AdministrationStrings.ChannelInitializationTimeout, connectionOriented.ChannelInitializationTimeout);
                        instance.SetProperty(AdministrationStrings.MaxBufferSize, connectionOriented.MaxBufferSize);
                        instance.SetProperty(AdministrationStrings.MaxPendingConnections, connectionOriented.MaxPendingConnections);
                        instance.SetProperty(AdministrationStrings.MaxOutputDelay, connectionOriented.MaxOutputDelay);
                        instance.SetProperty(AdministrationStrings.MaxPendingAccepts, connectionOriented.MaxPendingAccepts);
                        instance.SetProperty(AdministrationStrings.TransferMode, connectionOriented.TransferMode.ToString());

                        if (bindingElement is TcpTransportBindingElement)
                        {
                            TcpTransportBindingElement tcp = (TcpTransportBindingElement)bindingElement;
                            instance.SetProperty(AdministrationStrings.ListenBacklog, tcp.ListenBacklog);
                            instance.SetProperty(AdministrationStrings.PortSharingEnabled, tcp.PortSharingEnabled);
                            instance.SetProperty(AdministrationStrings.TeredoEnabled, tcp.TeredoEnabled);

                            IWmiInstance connectionPool = instance.NewInstance(AdministrationStrings.TcpConnectionPoolSettings);
                            connectionPool.SetProperty(AdministrationStrings.GroupName, tcp.ConnectionPoolSettings.GroupName);
                            connectionPool.SetProperty(AdministrationStrings.IdleTimeout, tcp.ConnectionPoolSettings.IdleTimeout);
                            connectionPool.SetProperty(AdministrationStrings.LeaseTimeout, tcp.ConnectionPoolSettings.LeaseTimeout);
                            connectionPool.SetProperty(AdministrationStrings.MaxOutboundConnectionsPerEndpoint, tcp.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint);

                            instance.SetProperty(AdministrationStrings.ConnectionPoolSettings, connectionPool);

                            FillExtendedProtectionPolicy(instance, tcp.ExtendedProtectionPolicy);
                        }
                        else if (bindingElement is NamedPipeTransportBindingElement)
                        {
                            NamedPipeTransportBindingElement namedPipe = (NamedPipeTransportBindingElement)bindingElement;
                            IWmiInstance connectionPool = instance.NewInstance(AdministrationStrings.NamedPipeConnectionPoolSettings);

                            connectionPool.SetProperty(AdministrationStrings.GroupName, namedPipe.ConnectionPoolSettings.GroupName);
                            connectionPool.SetProperty(AdministrationStrings.IdleTimeout, namedPipe.ConnectionPoolSettings.IdleTimeout);
                            connectionPool.SetProperty(AdministrationStrings.MaxOutboundConnectionsPerEndpoint, namedPipe.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint);

                            instance.SetProperty(AdministrationStrings.ConnectionPoolSettings, connectionPool);
                        }
                    }
                    else if (bindingElement is HttpTransportBindingElement)
                    {
                        HttpTransportBindingElement http = (HttpTransportBindingElement)bindingElement;
                        instance.SetProperty(AdministrationStrings.AllowCookies, http.AllowCookies);
                        instance.SetProperty(AdministrationStrings.AuthenticationScheme, http.AuthenticationScheme.ToString());

                        instance.SetProperty(AdministrationStrings.BypassProxyOnLocal, http.BypassProxyOnLocal);
                        instance.SetProperty(AdministrationStrings.DecompressionEnabled, http.DecompressionEnabled);
                        instance.SetProperty(AdministrationStrings.HostNameComparisonMode, http.HostNameComparisonMode.ToString());
                        instance.SetProperty(AdministrationStrings.KeepAliveEnabled, http.KeepAliveEnabled);
                        instance.SetProperty(AdministrationStrings.MaxBufferSize, http.MaxBufferSize);
                        if (null != http.ProxyAddress)
                        {
                            instance.SetProperty(AdministrationStrings.ProxyAddress, http.ProxyAddress.AbsoluteUri.ToString());
                        }
                        instance.SetProperty(AdministrationStrings.ProxyAuthenticationScheme, http.ProxyAuthenticationScheme.ToString());
                        instance.SetProperty(AdministrationStrings.Realm, http.Realm);
                        instance.SetProperty(AdministrationStrings.TransferMode, http.TransferMode.ToString());
                        instance.SetProperty(AdministrationStrings.UnsafeConnectionNtlmAuthentication, http.UnsafeConnectionNtlmAuthentication);
                        instance.SetProperty(AdministrationStrings.UseDefaultWebProxy, http.UseDefaultWebProxy);

                        FillExtendedProtectionPolicy(instance, http.ExtendedProtectionPolicy);

                        if (bindingElement is HttpsTransportBindingElement)
                        {
                            HttpsTransportBindingElement https = (HttpsTransportBindingElement)bindingElement;
                            instance.SetProperty(AdministrationStrings.RequireClientCertificate, https.RequireClientCertificate);
                        }
                    }
                    else if (bindingElement is MsmqBindingElementBase)
                    {
                        MsmqBindingElementBase msmq = (MsmqBindingElementBase)bindingElement;

                        if (null != msmq.CustomDeadLetterQueue)
                        {
                            instance.SetProperty(AdministrationStrings.CustomDeadLetterQueue, msmq.CustomDeadLetterQueue.AbsoluteUri.ToString());
                        }
                        instance.SetProperty(AdministrationStrings.DeadLetterQueue, msmq.DeadLetterQueue);
                        instance.SetProperty(AdministrationStrings.Durable, msmq.Durable);
                        instance.SetProperty(AdministrationStrings.ExactlyOnce, msmq.ExactlyOnce);
                        instance.SetProperty(AdministrationStrings.MaxRetryCycles, msmq.MaxRetryCycles);
                        instance.SetProperty(AdministrationStrings.ReceiveContextEnabled, msmq.ReceiveContextEnabled);
                        instance.SetProperty(AdministrationStrings.ReceiveErrorHandling, msmq.ReceiveErrorHandling);
                        instance.SetProperty(AdministrationStrings.ReceiveRetryCount, msmq.ReceiveRetryCount);
                        instance.SetProperty(AdministrationStrings.RetryCycleDelay, msmq.RetryCycleDelay);
                        instance.SetProperty(AdministrationStrings.TimeToLive, msmq.TimeToLive);
                        instance.SetProperty(AdministrationStrings.UseSourceJournal, msmq.UseSourceJournal);
                        instance.SetProperty(AdministrationStrings.UseMsmqTracing, msmq.UseMsmqTracing);
                        instance.SetProperty(AdministrationStrings.ValidityDuration, msmq.ValidityDuration);

                        MsmqTransportBindingElement msmqTransport = msmq as MsmqTransportBindingElement;
                        if (null != msmqTransport)
                        {
                            instance.SetProperty(AdministrationStrings.MaxPoolSize, msmqTransport.MaxPoolSize);
                            instance.SetProperty(AdministrationStrings.QueueTransferProtocol, msmqTransport.QueueTransferProtocol);
                            instance.SetProperty(AdministrationStrings.UseActiveDirectory, msmqTransport.UseActiveDirectory);
                        }

                        MsmqIntegrationBindingElement msmqIntegration = msmq as MsmqIntegrationBindingElement;
                        if (null != msmqIntegration)
                        {
                            instance.SetProperty(AdministrationStrings.SerializationFormat, msmqIntegration.SerializationFormat.ToString());
                        }
                    }
#pragma warning disable 0618
                    else if (bindingElement is PeerTransportBindingElement)
                    {
                        PeerTransportBindingElement peer = (PeerTransportBindingElement)bindingElement;
                        instance.SetProperty(AdministrationStrings.ListenIPAddress, peer.ListenIPAddress);
                        instance.SetProperty(AdministrationStrings.Port, peer.Port);

                        IWmiInstance securitySettings = instance.NewInstance(AdministrationStrings.PeerSecuritySettings);
                        securitySettings.SetProperty(AdministrationStrings.PeerSecurityMode, peer.Security.Mode.ToString());
                        IWmiInstance transportSecuritySettings = securitySettings.NewInstance(AdministrationStrings.PeerTransportSecuritySettings);
                        transportSecuritySettings.SetProperty(AdministrationStrings.PeerTransportCredentialType, peer.Security.Transport.CredentialType.ToString());
                        securitySettings.SetProperty(AdministrationStrings.Transport, transportSecuritySettings);
                        instance.SetProperty(AdministrationStrings.Security, securitySettings);
                    }
                }
                else if (bindingElement is PeerResolverBindingElement)
                {
                    PeerResolverBindingElement baseResolver = (PeerResolverBindingElement)bindingElement;
                    instance.SetProperty(AdministrationStrings.ReferralPolicy, baseResolver.ReferralPolicy.ToString());
                    if (bindingElement is PeerCustomResolverBindingElement)
                    {
                        PeerCustomResolverBindingElement specificElement = (PeerCustomResolverBindingElement)bindingElement;
                        if (specificElement.Address != null)
                        {
                            instance.SetProperty(AdministrationStrings.Address, specificElement.Address.ToString());
                        }
                        if (specificElement.Binding != null)
                        {
                            instance.SetProperty(AdministrationStrings.Binding, specificElement.Binding.ToString());
                        }
                    }
                }
#pragma warning restore 0618
                else if (bindingElement is ReliableSessionBindingElement)
                {
                    ReliableSessionBindingElement specificElement = (ReliableSessionBindingElement)bindingElement;
                    instance.SetProperty(AdministrationStrings.AcknowledgementInterval, specificElement.AcknowledgementInterval);
                    instance.SetProperty(AdministrationStrings.FlowControlEnabled, specificElement.FlowControlEnabled);
                    instance.SetProperty(AdministrationStrings.InactivityTimeout, specificElement.InactivityTimeout);
                    instance.SetProperty(AdministrationStrings.MaxPendingChannels, specificElement.MaxPendingChannels);
                    instance.SetProperty(AdministrationStrings.MaxRetryCount, specificElement.MaxRetryCount);
                    instance.SetProperty(AdministrationStrings.MaxTransferWindowSize, specificElement.MaxTransferWindowSize);
                    instance.SetProperty(AdministrationStrings.Ordered, specificElement.Ordered);
                    instance.SetProperty(AdministrationStrings.ReliableMessagingVersion, specificElement.ReliableMessagingVersion.ToString());
                }
                else if (bindingElement is SecurityBindingElement)
                {
                    SecurityBindingElement specificElement = (SecurityBindingElement)bindingElement;
                    instance.SetProperty(AdministrationStrings.AllowInsecureTransport, specificElement.AllowInsecureTransport);
                    instance.SetProperty(AdministrationStrings.DefaultAlgorithmSuite, specificElement.DefaultAlgorithmSuite.ToString());
                    instance.SetProperty(AdministrationStrings.EnableUnsecuredResponse, specificElement.EnableUnsecuredResponse);
                    instance.SetProperty(AdministrationStrings.IncludeTimestamp, specificElement.IncludeTimestamp);
                    instance.SetProperty(AdministrationStrings.KeyEntropyMode, specificElement.KeyEntropyMode.ToString());
                    instance.SetProperty(AdministrationStrings.SecurityHeaderLayout, specificElement.SecurityHeaderLayout.ToString());
                    instance.SetProperty(AdministrationStrings.MessageSecurityVersion, specificElement.MessageSecurityVersion.ToString());

                    IWmiInstance localServiceSecuritySettings = instance.NewInstance(AdministrationStrings.LocalServiceSecuritySettings);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.DetectReplays, specificElement.LocalServiceSettings.DetectReplays);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.InactivityTimeout, specificElement.LocalServiceSettings.InactivityTimeout);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.IssuedCookieLifetime, specificElement.LocalServiceSettings.IssuedCookieLifetime);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.MaxCachedCookies, specificElement.LocalServiceSettings.MaxCachedCookies);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.MaxClockSkew, specificElement.LocalServiceSettings.MaxClockSkew);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.MaxPendingSessions, specificElement.LocalServiceSettings.MaxPendingSessions);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.MaxStatefulNegotiations, specificElement.LocalServiceSettings.MaxStatefulNegotiations);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.NegotiationTimeout, specificElement.LocalServiceSettings.NegotiationTimeout);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.ReconnectTransportOnFailure, specificElement.LocalServiceSettings.ReconnectTransportOnFailure);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.ReplayCacheSize, specificElement.LocalServiceSettings.ReplayCacheSize);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.ReplayWindow, specificElement.LocalServiceSettings.ReplayWindow);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.SessionKeyRenewalInterval, specificElement.LocalServiceSettings.SessionKeyRenewalInterval);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.SessionKeyRolloverInterval, specificElement.LocalServiceSettings.SessionKeyRolloverInterval);
                    localServiceSecuritySettings.SetProperty(AdministrationStrings.TimestampValidityDuration, specificElement.LocalServiceSettings.TimestampValidityDuration);
                    instance.SetProperty(AdministrationStrings.LocalServiceSecuritySettings, localServiceSecuritySettings);

                    if (bindingElement is AsymmetricSecurityBindingElement)
                    {
                        AsymmetricSecurityBindingElement specificElement1 = (AsymmetricSecurityBindingElement)bindingElement;

                        instance.SetProperty(AdministrationStrings.MessageProtectionOrder, specificElement1.MessageProtectionOrder.ToString());
                        instance.SetProperty(AdministrationStrings.RequireSignatureConfirmation, specificElement1.RequireSignatureConfirmation);
                    }
                    else if (bindingElement is SymmetricSecurityBindingElement)
                    {
                        SymmetricSecurityBindingElement specificElement1 = (SymmetricSecurityBindingElement)bindingElement;

                        instance.SetProperty(AdministrationStrings.MessageProtectionOrder, specificElement1.MessageProtectionOrder.ToString());
                        instance.SetProperty(AdministrationStrings.RequireSignatureConfirmation, specificElement1.RequireSignatureConfirmation);
                    }
                }
                else if (bindingElement is WindowsStreamSecurityBindingElement)
                {
                    WindowsStreamSecurityBindingElement specificElement
                        = (WindowsStreamSecurityBindingElement)bindingElement;
                    instance.SetProperty(AdministrationStrings.ProtectionLevel, specificElement.ProtectionLevel.ToString());
                }
                else if (bindingElement is SslStreamSecurityBindingElement)
                {
                    SslStreamSecurityBindingElement specificElement = (SslStreamSecurityBindingElement)bindingElement;
                    instance.SetProperty(AdministrationStrings.RequireClientCertificate, specificElement.RequireClientCertificate);
                }
                else if (bindingElement is CompositeDuplexBindingElement)
                {
                    CompositeDuplexBindingElement specificElement = (CompositeDuplexBindingElement)bindingElement;
                    if (specificElement.ClientBaseAddress != null)
                    {
                        instance.SetProperty(AdministrationStrings.ClientBaseAddress, specificElement.ClientBaseAddress.AbsoluteUri);
                    }
                }
                else if (bindingElement is OneWayBindingElement)
                {
                    OneWayBindingElement oneWay = (OneWayBindingElement)bindingElement;
                    IWmiInstance         channelPoolSettings = instance.NewInstance(AdministrationStrings.ChannelPoolSettings);
                    channelPoolSettings.SetProperty(AdministrationStrings.IdleTimeout, oneWay.ChannelPoolSettings.IdleTimeout);
                    channelPoolSettings.SetProperty(AdministrationStrings.LeaseTimeout, oneWay.ChannelPoolSettings.LeaseTimeout);
                    channelPoolSettings.SetProperty(AdministrationStrings.MaxOutboundChannelsPerEndpoint, oneWay.ChannelPoolSettings.MaxOutboundChannelsPerEndpoint);
                    instance.SetProperty(AdministrationStrings.ChannelPoolSettings, channelPoolSettings);
                    instance.SetProperty(AdministrationStrings.PacketRoutable, oneWay.PacketRoutable);
                    instance.SetProperty(AdministrationStrings.MaxAcceptedChannels, oneWay.MaxAcceptedChannels);
                }
                else if (bindingElement is MessageEncodingBindingElement)
                {
                    MessageEncodingBindingElement encodingElement = (MessageEncodingBindingElement)bindingElement;

                    instance.SetProperty(AdministrationStrings.MessageVersion, encodingElement.MessageVersion.ToString());

                    if (bindingElement is BinaryMessageEncodingBindingElement)
                    {
                        BinaryMessageEncodingBindingElement specificElement = (BinaryMessageEncodingBindingElement)bindingElement;
                        instance.SetProperty(AdministrationStrings.MaxSessionSize, specificElement.MaxSessionSize);
                        instance.SetProperty(AdministrationStrings.MaxReadPoolSize, specificElement.MaxReadPoolSize);
                        instance.SetProperty(AdministrationStrings.MaxWritePoolSize, specificElement.MaxWritePoolSize);
                        if (null != specificElement.ReaderQuotas)
                        {
                            FillReaderQuotas(instance, specificElement.ReaderQuotas);
                        }
                        instance.SetProperty(AdministrationStrings.CompressionFormat, specificElement.CompressionFormat.ToString());
                    }
                    else if (bindingElement is TextMessageEncodingBindingElement)
                    {
                        TextMessageEncodingBindingElement specificElement = (TextMessageEncodingBindingElement)bindingElement;
                        instance.SetProperty(AdministrationStrings.Encoding, specificElement.WriteEncoding.WebName);
                        instance.SetProperty(AdministrationStrings.MaxReadPoolSize, specificElement.MaxReadPoolSize);
                        instance.SetProperty(AdministrationStrings.MaxWritePoolSize, specificElement.MaxWritePoolSize);
                        if (null != specificElement.ReaderQuotas)
                        {
                            FillReaderQuotas(instance, specificElement.ReaderQuotas);
                        }
                    }
                    else if (bindingElement is MtomMessageEncodingBindingElement)
                    {
                        MtomMessageEncodingBindingElement specificElement = (MtomMessageEncodingBindingElement)bindingElement;
                        instance.SetProperty(AdministrationStrings.Encoding, specificElement.WriteEncoding.WebName);
                        instance.SetProperty(AdministrationStrings.MessageVersion, specificElement.MessageVersion.ToString());
                        instance.SetProperty(AdministrationStrings.MaxReadPoolSize, specificElement.MaxReadPoolSize);
                        instance.SetProperty(AdministrationStrings.MaxWritePoolSize, specificElement.MaxWritePoolSize);
                        if (null != specificElement.ReaderQuotas)
                        {
                            FillReaderQuotas(instance, specificElement.ReaderQuotas);
                        }
                    }
                }
                else if (bindingElement is TransactionFlowBindingElement)
                {
                    TransactionFlowBindingElement specificElement = (TransactionFlowBindingElement)bindingElement;
                    instance.SetProperty(AdministrationStrings.TransactionFlow, specificElement.Transactions);
                    instance.SetProperty(AdministrationStrings.TransactionProtocol, specificElement.TransactionProtocol.ToString());
                    instance.SetProperty(AdministrationStrings.AllowWildcardAction, specificElement.AllowWildcardAction);
                }
                else if (bindingElement is PrivacyNoticeBindingElement)
                {
                    PrivacyNoticeBindingElement specificElement = (PrivacyNoticeBindingElement)bindingElement;
                    instance.SetProperty(AdministrationStrings.Url, specificElement.Url.ToString());
                    instance.SetProperty(AdministrationStrings.PrivacyNoticeVersion, specificElement.Version);
                }
            }
        }
        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);
        }
        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);
        }
 protected internal override BindingElement CreateBindingElement()
 {
     PrivacyNoticeBindingElement binding = new PrivacyNoticeBindingElement();
     this.ApplyConfiguration(binding);
     return binding;
 }
Beispiel #29
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            bool flag;

            binding = null;
            if (elements.Count > 5)
            {
                return(false);
            }
            PrivacyNoticeBindingElement privacyNoticeBindingElement = null;

            System.ServiceModel.Channels.ReliableSessionBindingElement reliableSessionBindingElement = null;
            SecurityBindingElement           securityBindingElement           = null;
            MessageEncodingBindingElement    messageEncodingBindingElement    = null;
            HttpRelayTransportBindingElement httpRelayTransportBindingElement = null;

            using (IEnumerator <BindingElement> enumerator = elements.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    BindingElement current = enumerator.Current;
                    if (current is SecurityBindingElement)
                    {
                        securityBindingElement = current as SecurityBindingElement;
                    }
                    else if (current is HttpsRelayTransportBindingElement)
                    {
                        httpRelayTransportBindingElement = current as HttpsRelayTransportBindingElement;
                    }
                    else if (current is HttpRelayTransportBindingElement)
                    {
                        httpRelayTransportBindingElement = current as HttpRelayTransportBindingElement;
                    }
                    else if (current is MessageEncodingBindingElement)
                    {
                        messageEncodingBindingElement = current as MessageEncodingBindingElement;
                    }
                    else if (current is System.ServiceModel.Channels.ReliableSessionBindingElement)
                    {
                        reliableSessionBindingElement = current as System.ServiceModel.Channels.ReliableSessionBindingElement;
                    }
                    else if (!(current is PrivacyNoticeBindingElement))
                    {
                        flag = false;
                        return(flag);
                    }
                    else
                    {
                        privacyNoticeBindingElement = current as PrivacyNoticeBindingElement;
                    }
                }
                if (httpRelayTransportBindingElement == null)
                {
                    return(false);
                }
                if (messageEncodingBindingElement == null)
                {
                    return(false);
                }
                if (privacyNoticeBindingElement != null || !WS2007HttpRelayBinding.TryCreate(securityBindingElement, httpRelayTransportBindingElement.RelayClientAuthenticationType, httpRelayTransportBindingElement, reliableSessionBindingElement, out binding))
                {
                    return(false);
                }
                WSHttpRelayBindingBase wSHttpRelayBindingBase = binding as WSHttpRelayBindingBase;
                wSHttpRelayBindingBase.InitializeFrom(httpRelayTransportBindingElement, messageEncodingBindingElement, reliableSessionBindingElement);
                if (!wSHttpRelayBindingBase.IsBindingElementsMatch(httpRelayTransportBindingElement, messageEncodingBindingElement, reliableSessionBindingElement))
                {
                    return(false);
                }
                return(true);
            }
            return(flag);
        }