private void CreateBinding()
        {
            Collection <BindingElement> bindingElementsInTopDownChannelStackOrder = new Collection <BindingElement>();
            BindingElement securityBindingElement = this.config.SecurityManager.GetSecurityBindingElement();

            if (securityBindingElement != null)
            {
                bindingElementsInTopDownChannelStackOrder.Add(securityBindingElement);
            }
            TcpTransportBindingElement item = new TcpTransportBindingElement {
                MaxReceivedMessageSize = this.config.MaxReceivedMessageSize,
                MaxBufferPoolSize      = this.config.MaxBufferPoolSize,
                TeredoEnabled          = true
            };
            MessageEncodingBindingElement encodingBindingElement = null;

            if (this.messageHandler != null)
            {
                encodingBindingElement = this.messageHandler.EncodingBindingElement;
            }
            if (encodingBindingElement == null)
            {
                BinaryMessageEncodingBindingElement element4 = new BinaryMessageEncodingBindingElement();
                this.config.ReaderQuotas.CopyTo(element4.ReaderQuotas);
                bindingElementsInTopDownChannelStackOrder.Add(element4);
            }
            else
            {
                bindingElementsInTopDownChannelStackOrder.Add(encodingBindingElement);
            }
            bindingElementsInTopDownChannelStackOrder.Add(item);
            this.binding = new CustomBinding(bindingElementsInTopDownChannelStackOrder);
            this.binding.ReceiveTimeout = TimeSpan.MaxValue;
        }
Example #2
0
        internal override bool IsMatch(BindingElement b)
        {
            if (!base.IsMatch(b))
            {
                return(false);
            }
            TcpTransportBindingElement element = b as TcpTransportBindingElement;

            if (element == null)
            {
                return(false);
            }
            if (this.listenBacklog != element.listenBacklog)
            {
                return(false);
            }
            if (this.portSharingEnabled != element.portSharingEnabled)
            {
                return(false);
            }
            if (this.teredoEnabled != element.teredoEnabled)
            {
                return(false);
            }
            if (!this.connectionPoolSettings.IsMatch(element.connectionPoolSettings))
            {
                return(false);
            }
            if (!ChannelBindingUtility.AreEqual(this.ExtendedProtectionPolicy, element.ExtendedProtectionPolicy))
            {
                return(false);
            }
            return(true);
        }
Example #3
0
        bool ImportTcpPolicy(MetadataImporter importer, PolicyConversionContext context,
                             WS.Soap12Binding soap)
        {
            var assertions = context.GetBindingAssertions();

            var tcpTransport = new TcpTransportBindingElement();

            var transportPolicy = PolicyImportHelper.GetTransportBindingPolicy(assertions);

            if (transportPolicy != null)
            {
                if (!ImportTcpTransport(importer, context, transportPolicy))
                {
                    return(false);
                }
                if (!ImportTransport(importer, tcpTransport, transportPolicy))
                {
                    return(false);
                }
            }

            var streamed = PolicyImportHelper.GetStreamedMessageFramingPolicy(assertions);

            if (streamed != null)
            {
                tcpTransport.TransferMode = TransferMode.Streamed;
            }

            context.BindingElements.Add(tcpTransport);
            return(true);
        }
Example #4
0
 protected TcpTransportBindingElement(TcpTransportBindingElement elementToBeCloned) : base(elementToBeCloned)
 {
     this.listenBacklog            = elementToBeCloned.listenBacklog;
     this.portSharingEnabled       = elementToBeCloned.portSharingEnabled;
     this.teredoEnabled            = elementToBeCloned.teredoEnabled;
     this.connectionPoolSettings   = elementToBeCloned.connectionPoolSettings.Clone();
     this.extendedProtectionPolicy = elementToBeCloned.ExtendedProtectionPolicy;
 }
 protected TcpTransportBindingElement(
     TcpTransportBindingElement other)
     : base(other)
 {
     listen_backlog       = other.listen_backlog;
     port_sharing_enabled = other.port_sharing_enabled;
     pool.CopyPropertiesFrom(other.pool);
 }
 protected TcpTransportBindingElement(
     TcpTransportBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
     listen_backlog       = elementToBeCloned.listen_backlog;
     port_sharing_enabled = elementToBeCloned.port_sharing_enabled;
     pool.CopyPropertiesFrom(elementToBeCloned.pool);
 }
 public TcpChannelFactory(TcpTransportBindingElement bindingElement, BindingContext context)
     : base(bindingElement, context,
            bindingElement.ConnectionPoolSettings.GroupName,
            bindingElement.ConnectionPoolSettings.IdleTimeout,
            bindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint,
            true)
 {
     this.leaseTimeout = bindingElement.ConnectionPoolSettings.LeaseTimeout;
 }
Example #8
0
        /// <summary>
        /// Initializes the binding.
        /// </summary>
        /// <param name="namespaceUris">The namespace uris.</param>
        /// <param name="factory">The factory.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="description">The description.</param>
        public UaSoapXmlOverTcpBinding(
            NamespaceTable namespaceUris,
            EncodeableFactory factory,
            EndpointConfiguration configuration,
            EndpointDescription description)
            :
            base(namespaceUris, factory, configuration)
        {
            if (description != null && description.SecurityMode != MessageSecurityMode.None)
            {
                SymmetricSecurityBindingElement bootstrap = (SymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement();

                bootstrap.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature;
                bootstrap.DefaultAlgorithmSuite  = SecurityPolicies.ToSecurityAlgorithmSuite(description.SecurityPolicyUri);
                bootstrap.IncludeTimestamp       = true;
                bootstrap.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
                // bootstrap.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
                bootstrap.RequireSignatureConfirmation = false;
                bootstrap.SecurityHeaderLayout         = SecurityHeaderLayout.Strict;

                m_security = (SymmetricSecurityBindingElement)SecurityBindingElement.CreateSecureConversationBindingElement(bootstrap, true);

                m_security.MessageProtectionOrder = MessageProtectionOrder.EncryptBeforeSign;
                m_security.DefaultAlgorithmSuite  = SecurityPolicies.ToSecurityAlgorithmSuite(description.SecurityPolicyUri);
                m_security.IncludeTimestamp       = true;
                m_security.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
                // m_security.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
                m_security.RequireSignatureConfirmation = false;
                m_security.SecurityHeaderLayout         = SecurityHeaderLayout.Strict;

                m_security.SetKeyDerivation(true);
            }

            m_encoding = new BinaryMessageEncodingBindingElement();

            // WCF does not distinguish between arrays and byte string.
            int maxArrayLength = configuration.MaxArrayLength;

            if (configuration.MaxArrayLength < configuration.MaxByteStringLength)
            {
                maxArrayLength = configuration.MaxByteStringLength;
            }

            m_encoding.ReaderQuotas.MaxArrayLength         = maxArrayLength;
            m_encoding.ReaderQuotas.MaxStringContentLength = configuration.MaxStringLength;
            m_encoding.ReaderQuotas.MaxBytesPerRead        = Int32.MaxValue;
            m_encoding.ReaderQuotas.MaxDepth = Int32.MaxValue;
            m_encoding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;

            m_transport = new System.ServiceModel.Channels.TcpTransportBindingElement();

            m_transport.ManualAddressing       = false;
            m_transport.MaxBufferPoolSize      = Int32.MaxValue;
            m_transport.MaxReceivedMessageSize = configuration.MaxMessageSize;
        }
        /// <summary>
        /// Initializes the binding.
        /// </summary>
        /// <param name="namespaceUris">The namespace uris.</param>
        /// <param name="factory">The factory.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="description">The description.</param>
        public UaSoapXmlOverTcpBinding(
            NamespaceTable        namespaceUris,
            EncodeableFactory     factory,
            EndpointConfiguration configuration,
            EndpointDescription   description)
        :
            base(namespaceUris, factory, configuration)
        {                   
            if (description != null && description.SecurityMode != MessageSecurityMode.None)
            {
                SymmetricSecurityBindingElement bootstrap = (SymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement();
                
                bootstrap.MessageProtectionOrder       = MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature;
                bootstrap.DefaultAlgorithmSuite        = SecurityPolicies.ToSecurityAlgorithmSuite(description.SecurityPolicyUri);
                bootstrap.IncludeTimestamp             = true;
                bootstrap.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
                // bootstrap.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
                bootstrap.RequireSignatureConfirmation = false;
                bootstrap.SecurityHeaderLayout         = SecurityHeaderLayout.Strict;
                
                m_security = (SymmetricSecurityBindingElement)SecurityBindingElement.CreateSecureConversationBindingElement(bootstrap, true);
                
                m_security.MessageProtectionOrder       = MessageProtectionOrder.EncryptBeforeSign;
                m_security.DefaultAlgorithmSuite        = SecurityPolicies.ToSecurityAlgorithmSuite(description.SecurityPolicyUri);
                m_security.IncludeTimestamp             = true;
                m_security.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
                // m_security.MessageSecurityVersion       = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
                m_security.RequireSignatureConfirmation = false;
                m_security.SecurityHeaderLayout         = SecurityHeaderLayout.Strict;

                m_security.SetKeyDerivation(true);
            }
            
            m_encoding = new BinaryMessageEncodingBindingElement();
           
            // WCF does not distinguish between arrays and byte string.
            int maxArrayLength = configuration.MaxArrayLength;

            if (configuration.MaxArrayLength < configuration.MaxByteStringLength)
            {
                maxArrayLength = configuration.MaxByteStringLength;
            }

            m_encoding.ReaderQuotas.MaxArrayLength         = maxArrayLength;
            m_encoding.ReaderQuotas.MaxStringContentLength = configuration.MaxStringLength;
            m_encoding.ReaderQuotas.MaxBytesPerRead        = Int32.MaxValue;
            m_encoding.ReaderQuotas.MaxDepth               = Int32.MaxValue;
            m_encoding.ReaderQuotas.MaxNameTableCharCount  = Int32.MaxValue;

            m_transport = new System.ServiceModel.Channels.TcpTransportBindingElement();

            m_transport.ManualAddressing       = false;
            m_transport.MaxBufferPoolSize      = Int32.MaxValue;
            m_transport.MaxReceivedMessageSize = configuration.MaxMessageSize;
        }
 protected TcpChannelListener(TcpTransportBindingElement bindingElement, BindingContext context) : base(bindingElement, context)
 {
     this.listenBacklog            = bindingElement.ListenBacklog;
     this.portSharingEnabled       = bindingElement.PortSharingEnabled;
     this.teredoEnabled            = bindingElement.TeredoEnabled;
     this.extendedProtectionPolicy = bindingElement.ExtendedProtectionPolicy;
     base.SetIdleTimeout(bindingElement.ConnectionPoolSettings.IdleTimeout);
     base.SetMaxPooledConnections(bindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint);
     if (!bindingElement.PortSharingEnabled && (context.ListenUriMode == ListenUriMode.Unique))
     {
         this.SetupUniquePort(context);
     }
 }
        static TransportBindingElement CreateTransportBindingElements(string transportUri, PolicyConversionContext policyContext)
        {
            TransportBindingElement transportBindingElement = null;

            // Try and Create TransportBindingElement
            switch (transportUri)
            {
            case TransportPolicyConstants.HttpTransportUri:
                transportBindingElement = GetHttpTransportBindingElement(policyContext);
                break;

            case TransportPolicyConstants.TcpTransportUri:
                transportBindingElement = new TcpTransportBindingElement();
                break;

            case TransportPolicyConstants.NamedPipeTransportUri:
                transportBindingElement = new NamedPipeTransportBindingElement();
                break;

            case TransportPolicyConstants.MsmqTransportUri:
                transportBindingElement = new MsmqTransportBindingElement();
                break;

            case TransportPolicyConstants.PeerTransportUri:
#pragma warning disable 0618
                transportBindingElement = new PeerTransportBindingElement();
#pragma warning restore 0618
                break;

            case TransportPolicyConstants.WebSocketTransportUri:
                HttpTransportBindingElement httpTransport = GetHttpTransportBindingElement(policyContext);
                httpTransport.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
                httpTransport.WebSocketSettings.SubProtocol    = WebSocketTransportSettings.SoapSubProtocol;
                transportBindingElement = httpTransport;
                break;

            default:
                // There may be another registered converter that can handle this transport.
                break;
            }

            return(transportBindingElement);
        }
Example #12
0
        public TcpChannelFactory(TcpTransportBindingElement source, BindingContext ctx)
        {
            MessageEncoder            encoder = null;
            XmlDictionaryReaderQuotas quotas  = null;

            foreach (BindingElement be in ctx.RemainingBindingElements)
            {
                MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement;
                if (mbe != null)
                {
                    encoder = CreateEncoder <TChannel> (mbe);
                    quotas  = mbe.GetProperty <XmlDictionaryReaderQuotas> (ctx);
                    break;
                }
            }
            if (encoder == null)
            {
                encoder = new BinaryMessageEncoder();
            }
            info = new TcpChannelInfo(source, encoder, quotas);
        }
        internal override bool IsMatch(BindingElement b)
        {
            if (!base.IsMatch(b))
            {
                return(false);
            }

            TcpTransportBindingElement tcp = b as TcpTransportBindingElement;

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

            if (!ConnectionPoolSettings.IsMatch(tcp.ConnectionPoolSettings))
            {
                return(false);
            }

            return(true);
        }
Example #14
0
        private NetTcpBinding CreateTcpBinding()
        {
            NetTcpBinding tcpBinding = new NetTcpBinding();

            System.ServiceModel.Channels.BindingElementCollection bElementCollection = tcpBinding.CreateBindingElements();

            tcpBinding.Name                   = "SeymourSkinner";
            tcpBinding.CloseTimeout           = TimeSpan.FromHours(2); // new TimeSpan(1, 0, 0); // 1 hora
            tcpBinding.OpenTimeout            = TimeSpan.FromHours(2); // new TimeSpan(1, 0, 0); // 1 hora
            tcpBinding.ReceiveTimeout         = TimeSpan.FromHours(2); // new TimeSpan(1, 0, 0); // 1 hora
            tcpBinding.SendTimeout            = TimeSpan.FromHours(2); // new TimeSpan(1, 0, 0); // 1 hora
            tcpBinding.MaxBufferPoolSize      = 2147483647;
            tcpBinding.MaxBufferSize          = 2147483647;
            tcpBinding.MaxReceivedMessageSize = 2147483647;

            tcpBinding.ReliableSession.InactivityTimeout = new TimeSpan(1, 0, 0);
            tcpBinding.Security.Mode = SecurityMode.None;

            System.ServiceModel.Channels.TcpTransportBindingElement tcp = bElementCollection.Find <System.ServiceModel.Channels.TcpTransportBindingElement>();
            tcp.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 500;
            tcp.ConnectionPoolSettings.LeaseTimeout = TimeSpan.MaxValue;
            tcp.ConnectionPoolSettings.IdleTimeout  = TimeSpan.MaxValue;
            tcp.ChannelInitializationTimeout        = TimeSpan.MaxValue;
            tcp.ConnectionBufferSize   = int.MaxValue;
            tcp.MaxBufferPoolSize      = long.MaxValue;
            tcp.MaxBufferSize          = int.MaxValue;
            tcp.MaxReceivedMessageSize = long.MaxValue;

            XmlDictionaryReaderQuotas quotas = tcpBinding.ReaderQuotas;

            quotas.MaxStringContentLength = int.MaxValue;
            quotas.MaxArrayLength         = int.MaxValue;
            quotas.MaxBytesPerRead        = int.MaxValue;
            quotas.MaxDepth = int.MaxValue;
            quotas.MaxNameTableCharCount = int.MaxValue;

            tcpBinding.GetType().GetProperty("ReaderQuotas").SetValue(tcpBinding, quotas, null);

            return(tcpBinding);
        }
Example #15
0
        // Create the binding using user specified config. The stacking is
        // BinaryMessageEncoder/TCP
        void CreateBinding()
        {
            Collection <BindingElement> bindingElements = new Collection <BindingElement>();
            BindingElement security = this.config.SecurityManager.GetSecurityBindingElement();

            if (security != null)
            {
                bindingElements.Add(security);
            }

            TcpTransportBindingElement transport = new TcpTransportBindingElement();

            transport.MaxReceivedMessageSize = this.config.MaxReceivedMessageSize;
            transport.MaxBufferPoolSize      = this.config.MaxBufferPoolSize;
            transport.TeredoEnabled          = true;

            MessageEncodingBindingElement encoder = null;

            if (messageHandler != null)
            {
                encoder = messageHandler.EncodingBindingElement;
            }

            if (encoder == null)
            {
                BinaryMessageEncodingBindingElement bencoder = new BinaryMessageEncodingBindingElement();
                this.config.ReaderQuotas.CopyTo(bencoder.ReaderQuotas);
                bindingElements.Add(bencoder);
            }
            else
            {
                bindingElements.Add(encoder);
            }

            bindingElements.Add(transport);

            this.binding = new CustomBinding(bindingElements);
            this.binding.ReceiveTimeout = TimeSpan.MaxValue;
        }
Example #16
0
        public TcpChannelListener(TcpTransportBindingElement source, BindingContext context)
            : base(context)
        {
            XmlDictionaryReaderQuotas quotas = null;

            foreach (BindingElement be in context.Binding.Elements)
            {
                MessageEncodingBindingElement mbe = be as MessageEncodingBindingElement;
                if (mbe != null)
                {
                    MessageEncoder = CreateEncoder <TChannel> (mbe);
                    quotas         = mbe.GetProperty <XmlDictionaryReaderQuotas> (context);
                    break;
                }
            }

            if (MessageEncoder == null)
            {
                MessageEncoder = new BinaryMessageEncoder();
            }

            info = new TcpChannelInfo(source, MessageEncoder, quotas);
        }
        public void Start()
        {
            Logging.Log(LogLevelEnum.Info, "Starting WCF service");
            ServiceAddress    = string.Format("net.tcp://{0}:{1}/", Utilities.GetIPv4Address(Settings.Instance.UseLoopback).ToString(), Settings.Instance.WcfPort);
            MexServiceAddress = string.Format("net.tcp://{0}:{1}/mex/", Utilities.GetIPv4Address().ToString(), Settings.Instance.WcfMexPort);
            Logging.Log(LogLevelEnum.Debug, string.Format("Service host address: {0}", ServiceAddress));
            Logging.Log(LogLevelEnum.Debug, string.Format("MEX Service host address: {0}", MexServiceAddress));
            serviceHost = new ServiceModel.ServiceHost(typeof(TService), new Uri(ServiceAddress));
            serviceHost.AddServiceEndpoint(typeof(TContract), new ServiceModel.NetTcpBinding(ServiceModel.SecurityMode.None), "");

            // Add TCP MEX endpoint
            ServiceModelChannels.BindingElement             bindingElement   = new ServiceModelChannels.TcpTransportBindingElement();
            ServiceModelChannels.CustomBinding              binding          = new ServiceModelChannels.CustomBinding(bindingElement);
            ServiceModelDescription.ServiceMetadataBehavior metadataBehavior = serviceHost.Description.Behaviors.Find <ServiceModelDescription.ServiceMetadataBehavior>();
            if (metadataBehavior == null)
            {
                metadataBehavior = new ServiceModelDescription.ServiceMetadataBehavior();
                serviceHost.Description.Behaviors.Add(metadataBehavior);
            }
            serviceHost.AddServiceEndpoint(typeof(ServiceModelDescription.IMetadataExchange), binding, MexServiceAddress);

            serviceHost.Open();
            Logging.Log(LogLevelEnum.Info, "WCF service started");
        }
        private static TransportBindingElement CreateTransportBindingElements(string transportUri, PolicyConversionContext policyContext)
        {
            TransportBindingElement transportBindingElement = null;

            // Try and Create TransportBindingElement
            switch (transportUri)
            {
            case TransportPolicyConstants.HttpTransportUri:
                transportBindingElement = GetHttpTransportBindingElement(policyContext);
                break;

            case TransportPolicyConstants.TcpTransportUri:
                transportBindingElement = new TcpTransportBindingElement();
                break;

            case TransportPolicyConstants.NamedPipeTransportUri:
            // Not supported on .NET Core yet.
            //                     transportBindingElement = new NamedPipeTransportBindingElement();
            //                     break;
            case TransportPolicyConstants.PeerTransportUri:
                throw new NotImplementedException();

            case TransportPolicyConstants.WebSocketTransportUri:
                HttpTransportBindingElement httpTransport = GetHttpTransportBindingElement(policyContext);
                httpTransport.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
                httpTransport.WebSocketSettings.SubProtocol    = WebSocketTransportSettings.SoapSubProtocol;
                transportBindingElement = httpTransport;
                break;

            default:
                // There may be another registered converter that can handle this transport.
                break;
            }

            return(transportBindingElement);
        }
Example #19
0
 public TcpDuplexChannelListener(TcpTransportBindingElement bindingElement, BindingContext context) : base(bindingElement, context)
 {
     this.duplexAcceptor = new InputQueueChannelAcceptor <IDuplexSessionChannel>(this);
 }
Example #20
0
 protected TcpChannelListener(TcpTransportBindingElement bindingElement, BindingContext context)
     : base(bindingElement, context)
 {
 }
Example #21
0
 public TcpBindingProperties(TcpTransportBindingElement source)
 {
     this.source = source;
 }
 public TcpReplyChannelListener(TcpTransportBindingElement bindingElement, BindingContext context) : base(bindingElement, context)
 {
     this.replyAcceptor = new ConnectionOrientedTransportChannelListener.ConnectionOrientedTransportReplyChannelAcceptor(this);
 }
Example #23
0
        bool ImportNetTcpBinding(
            WsdlImporter importer, WsdlEndpointConversionContext context,
            CustomBinding custom, WS.Soap12Binding soap)
        {
            TcpTransportBindingElement          transportElement       = null;
            BinaryMessageEncodingBindingElement binaryElement          = null;
            TransactionFlowBindingElement       transactionFlowElement = null;
            WindowsStreamSecurityBindingElement windowsStreamElement   = null;
            SslStreamSecurityBindingElement     sslStreamElement       = null;
            bool foundUnknownElement = false;

            foreach (var element in custom.Elements)
            {
                if (element is TcpTransportBindingElement)
                {
                    transportElement = (TcpTransportBindingElement)element;
                }
                else if (element is BinaryMessageEncodingBindingElement)
                {
                    binaryElement = (BinaryMessageEncodingBindingElement)element;
                }
                else if (element is TransactionFlowBindingElement)
                {
                    transactionFlowElement = (TransactionFlowBindingElement)element;
                }
                else if (element is WindowsStreamSecurityBindingElement)
                {
                    windowsStreamElement = (WindowsStreamSecurityBindingElement)element;
                }
                else if (element is SslStreamSecurityBindingElement)
                {
                    sslStreamElement = (SslStreamSecurityBindingElement)element;
                }
                else
                {
                    importer.AddWarning(
                        "Found unknown binding element `{0}' while importing " +
                        "binding `{1}'.", element.GetType(), custom.Name);
                    foundUnknownElement = true;
                }
            }

            if (foundUnknownElement)
            {
                return(false);
            }

            if (transportElement == null)
            {
                importer.AddWarning(
                    "Missing TcpTransportBindingElement while importing " +
                    "binding `{0}'.", custom.Name);
                return(false);
            }
            if (binaryElement == null)
            {
                importer.AddWarning(
                    "Missing BinaryMessageEncodingBindingElement while importing " +
                    "binding `{0}'.", custom.Name);
                return(false);
            }

            if ((windowsStreamElement != null) && (sslStreamElement != null))
            {
                importer.AddWarning(
                    "Found both WindowsStreamSecurityBindingElement and " +
                    "SslStreamSecurityBindingElement while importing binding `{0}.",
                    custom.Name);
                return(false);
            }

            NetTcpSecurity security;

            if (windowsStreamElement != null)
            {
                security = new NetTcpSecurity(SecurityMode.Transport);
                security.Transport.ProtectionLevel = windowsStreamElement.ProtectionLevel;
            }
            else if (sslStreamElement != null)
            {
                security = new NetTcpSecurity(SecurityMode.TransportWithMessageCredential);
            }
            else
            {
                security = new NetTcpSecurity(SecurityMode.None);
            }

            var netTcp = new NetTcpBinding(transportElement, security, false);

            netTcp.Name      = context.Endpoint.Binding.Name;
            netTcp.Namespace = context.Endpoint.Binding.Namespace;

            context.Endpoint.Binding = netTcp;
            return(true);
        }
 protected TcpTransportBindingElement(TcpTransportBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
     ConnectionPoolSettings    = elementToBeCloned.ConnectionPoolSettings.Clone();
     _extendedProtectionPolicy = elementToBeCloned._extendedProtectionPolicy;
 }
Example #25
0
 protected TcpTransportBindingElement(TcpTransportBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
     _connectionPoolSettings = elementToBeCloned._connectionPoolSettings.Clone();
     _portSharingEnabled     = elementToBeCloned._portSharingEnabled;
 }