internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count != 3)
            {
                return(false);
            }
            PeerResolverBindingElement          element   = null;
            PeerTransportBindingElement         transport = null;
            BinaryMessageEncodingBindingElement encoding  = null;

            foreach (BindingElement element4 in elements)
            {
                if (element4 is TransportBindingElement)
                {
                    transport = element4 as PeerTransportBindingElement;
                }
                else if (element4 is BinaryMessageEncodingBindingElement)
                {
                    encoding = element4 as BinaryMessageEncodingBindingElement;
                }
                else if (element4 is PeerResolverBindingElement)
                {
                    element = element4 as PeerResolverBindingElement;
                }
                else
                {
                    return(false);
                }
            }
            if (transport == null)
            {
                return(false);
            }
            if (encoding == null)
            {
                return(false);
            }
            if (element == null)
            {
                return(false);
            }
            NetPeerTcpBinding binding2 = new NetPeerTcpBinding();

            binding2.InitializeFrom(transport, encoding);
            if (!binding2.IsBindingElementsMatch(transport, encoding))
            {
                return(false);
            }
            PeerCustomResolverBindingElement element5 = element as PeerCustomResolverBindingElement;

            if (element5 != null)
            {
                binding2.Resolver.Custom.Address  = element5.Address;
                binding2.Resolver.Custom.Binding  = element5.Binding;
                binding2.Resolver.Custom.Resolver = element5.CreatePeerResolver();
            }
            else if ((element is PnrpPeerResolverBindingElement) && IsPnrpAvailable)
            {
                binding2.Resolver.Mode = PeerResolverMode.Pnrp;
            }
            binding = binding2;
            return(true);
        }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count != 3)
            {
                return(false);
            }

            PeerResolverBindingElement          resolver  = null;
            PeerTransportBindingElement         transport = null;
            BinaryMessageEncodingBindingElement encoding  = null;

            foreach (BindingElement element in elements)
            {
                if (element is TransportBindingElement)
                {
                    transport = element as PeerTransportBindingElement;
                }
                else if (element is BinaryMessageEncodingBindingElement)
                {
                    encoding = element as BinaryMessageEncodingBindingElement;
                }
                else if (element is PeerResolverBindingElement)
                {
                    resolver = element as PeerResolverBindingElement;
                }
                else
                {
                    return(false);
                }
            }

            if (transport == null)
            {
                return(false);
            }

            if (encoding == null)
            {
                return(false);
            }

            if (resolver == null)
            {
                return(false);
            }

            NetPeerTcpBinding netPeerTcpBinding = new NetPeerTcpBinding();

            netPeerTcpBinding.InitializeFrom(transport, encoding);
            if (!netPeerTcpBinding.IsBindingElementsMatch(transport, encoding))
            {
                return(false);
            }

            PeerCustomResolverBindingElement customResolver = resolver as PeerCustomResolverBindingElement;

            if (customResolver != null)
            {
                netPeerTcpBinding.Resolver.Custom.Address  = customResolver.Address;
                netPeerTcpBinding.Resolver.Custom.Binding  = customResolver.Binding;
                netPeerTcpBinding.Resolver.Custom.Resolver = customResolver.CreatePeerResolver();
            }
            else if (resolver is PnrpPeerResolverBindingElement)
            {
                if (NetPeerTcpBinding.IsPnrpAvailable)
                {
                    netPeerTcpBinding.Resolver.Mode = PeerResolverMode.Pnrp;
                }
            }
            binding = netPeerTcpBinding;
            return(true);
        }
 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);
             }
         }
     }
 }