Пример #1
0
 /// <summary>
 /// Initializes the binding with another binding.
 /// </summary>
 public UaTcpTransportBindingElement(UaTcpTransportBindingElement source) : base(source)
 {
     m_descriptions          = source.m_descriptions;
     m_configuration         = source.m_configuration;
     m_channelLifetime       = source.m_channelLifetime;
     m_securityTokenLifetime = source.m_securityTokenLifetime;
     m_messageContext        = source.m_messageContext;
     m_serviceHost           = source.ServiceHost;
 }
        /// <summary>
        /// Initializes the listener from a binding element.
        /// </summary>
        internal UaTcpChannelListener(UaTcpTransportBindingElement bindingElement, BindingContext context)
            :
            base(context.Binding)
        {
            // assign a unique guid to the listener.
            m_listenerId = Guid.NewGuid().ToString();

            SetUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);

            m_descriptions  = bindingElement.Descriptions;
            m_configuration = bindingElement.Configuration;

            m_quotas = new TcpChannelQuotas();

            m_quotas.MaxBufferSize         = m_configuration.MaxBufferSize;
            m_quotas.MaxMessageSize        = m_configuration.MaxMessageSize;
            m_quotas.ChannelLifetime       = m_configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = m_configuration.SecurityTokenLifetime;
            m_quotas.MessageContext        = bindingElement.MessageContext;

            foreach (object parameter in context.BindingParameters)
            {
                ServiceCredentials credentials = parameter as ServiceCredentials;

                if (credentials != null)
                {
                    // TBD - paste the cert with the private key with the additional chain.
                    m_serverCertificate           = CertificateFactory.Create(credentials.ServiceCertificate.Certificate, credentials.ServiceCertificate.Certificate);
                    m_quotas.CertificateValidator = credentials.ClientCertificate.Authentication.CustomCertificateValidator;
                }
            }

            m_bufferManager = new BufferManager("Server", (int)bindingElement.MaxBufferPoolSize, m_quotas.MaxBufferSize);

            m_channels     = new Dictionary <uint, TcpServerChannel>();
            m_channelQueue = new Queue <UaTcpReplyChannel>();
            m_acceptQueue  = new Queue <TcpAsyncOperation <IReplySessionChannel> >();

            // link the channel directly to the server.
            // this is a hack designed to work around a bug in the WCF framework that results in lost requests during stress testing.
            if (bindingElement.ServiceHost != null)
            {
                if (bindingElement.ServiceHost.Server is DiscoveryServerBase)
                {
                    m_callback = new DiscoveryEndpoint(bindingElement.ServiceHost);
                }
                else
                {
                    m_callback = new SessionEndpoint(bindingElement.ServiceHost);
                }
            }
        }
Пример #3
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="descriptions">The descriptions.</param>
        public UaTcpBinding(
            NamespaceTable namespaceUris,
            EncodeableFactory factory,
            EndpointConfiguration configuration,
            params EndpointDescription[] descriptions)
            :
            base(namespaceUris, factory, configuration)
        {
            m_transport = new UaTcpTransportBindingElement();

            m_transport.MessageContext = base.MessageContext;
            m_transport.Configuration  = configuration;

            if (descriptions != null)
            {
                m_transport.Descriptions = new EndpointDescriptionCollection(descriptions);
            }

            m_transport.MaxBufferPoolSize      = Int32.MaxValue;
            m_transport.MaxReceivedMessageSize = configuration.MaxMessageSize;
        }
        /// <summary>
        /// Initializes the listener from a binding element.
        /// </summary>
        public UaTcpChannelFactory(UaTcpTransportBindingElement bindingElement, BindingContext context) : base(context.Binding)
        {
            // assign a unique id to the instance.
            m_id = Guid.NewGuid().ToString();

            // initialize the quotas from the binding configuration.
            EndpointConfiguration configuration = bindingElement.Configuration;

            m_quotas = new TcpChannelQuotas();

            m_quotas.MaxBufferSize         = configuration.MaxBufferSize;
            m_quotas.MaxMessageSize        = configuration.MaxMessageSize;
            m_quotas.ChannelLifetime       = configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = configuration.SecurityTokenLifetime;
            m_quotas.MessageContext        = bindingElement.MessageContext;

            m_bufferManager = new BufferManager("Client", (int)bindingElement.MaxBufferPoolSize, m_quotas.MaxBufferSize);

            // extract the security mode from the endpoint description.
            m_endpointDescription = null;

            if (bindingElement.Descriptions != null && bindingElement.Descriptions.Count > 0)
            {
                m_endpointDescription = bindingElement.Descriptions[0];
            }

            // find the client credentials in the binding parameters.
            foreach (object parameter in context.BindingParameters)
            {
                ClientCredentials credentials = parameter as ClientCredentials;

                if (credentials != null)
                {
                    m_credentials = credentials;
                    m_quotas.CertificateValidator = credentials.ServiceCertificate.Authentication.CustomCertificateValidator;
                    break;
                }
            }
        }