Stores various configuration parameters used by the channel.
Ejemplo n.º 1
0
        /// <summary>
        /// Opens the listener and starts accepting connection.
        /// </summary>
        /// <param name="baseAddress">The base address.</param>
        /// <param name="settings">The settings to use when creating the listener.</param>
        /// <param name="callback">The callback to use when requests arrive via the channel.</param>
        /// <exception cref="ArgumentNullException">Thrown if any parameter is null.</exception>
        /// <exception cref="ServiceResultException">Thrown if any communication error occurs.</exception>
        public void Open(Uri baseAddress, TransportListenerSettings settings, ITransportListenerCallback callback)
        {
            // assign a unique guid to the listener.
            m_listenerId = Guid.NewGuid().ToString();

            m_uri           = baseAddress;
            m_descriptions  = settings.Descriptions;
            m_configuration = settings.Configuration;

            // initialize the quotas.
            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 = new ServiceMessageContext();

            m_quotas.MessageContext.MaxArrayLength      = m_configuration.MaxArrayLength;
            m_quotas.MessageContext.MaxByteStringLength = m_configuration.MaxByteStringLength;
            m_quotas.MessageContext.MaxMessageSize      = m_configuration.MaxMessageSize;
            m_quotas.MessageContext.MaxStringLength     = m_configuration.MaxStringLength;
            m_quotas.MessageContext.NamespaceUris       = settings.NamespaceUris;
            m_quotas.MessageContext.ServerUris          = new StringTable();
            m_quotas.MessageContext.Factory             = settings.Factory;

            m_quotas.CertificateValidator = settings.CertificateValidator;

            // save the callback to the server.
            m_callback = callback;

            // start the listener.
            Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the channel with a channel manager.
        /// </summary>
        internal UaTcpRequestChannel(
            ChannelManagerBase manager,
            string factoryId,
            EndpointAddress address,
            Uri via,
            BufferManager bufferManager,
            TcpChannelQuotas quotas,
            X509Certificate2 clientCertificate,
            X509Certificate2 serverCertificate,
            EndpointDescription endpointDescription)
            :
            base(manager)
        {
            m_factoryId = factoryId;
            m_address   = address;
            m_via       = via;
            m_quotas    = quotas;

            m_channel = new TcpClientChannel(
                m_factoryId,
                bufferManager,
                quotas,
                clientCertificate,
                serverCertificate,
                endpointDescription);

            m_ResponseCallack = new AsyncCallback(OnResponse);
        }
        /// <summary>
        /// Saves the settings so the channel can be opened later.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="settings">The settings.</param>
        private void SaveSettings(Uri url, TransportChannelSettings settings)
        {
            // save the settings.
            m_url              = url;
            m_settings         = settings;
            m_operationTimeout = settings.Configuration.OperationTimeout;

            // initialize the quotas.
            m_quotas = new TcpChannelQuotas();

            m_quotas.MaxBufferSize         = m_settings.Configuration.MaxBufferSize;
            m_quotas.MaxMessageSize        = m_settings.Configuration.MaxMessageSize;
            m_quotas.ChannelLifetime       = m_settings.Configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = m_settings.Configuration.SecurityTokenLifetime;

            m_quotas.MessageContext = new ServiceMessageContext();

            m_quotas.MessageContext.MaxArrayLength      = m_settings.Configuration.MaxArrayLength;
            m_quotas.MessageContext.MaxByteStringLength = m_settings.Configuration.MaxByteStringLength;
            m_quotas.MessageContext.MaxMessageSize      = m_settings.Configuration.MaxMessageSize;
            m_quotas.MessageContext.MaxStringLength     = m_settings.Configuration.MaxStringLength;
            m_quotas.MessageContext.NamespaceUris       = m_settings.NamespaceUris;
            m_quotas.MessageContext.ServerUris          = new StringTable();
            m_quotas.MessageContext.Factory             = m_settings.Factory;

            m_quotas.CertificateValidator = settings.CertificateValidator;

            // create the buffer manager.
            m_bufferManager = new BufferManager("Client", (int)Int32.MaxValue, settings.Configuration.MaxBufferSize);
        }
Ejemplo n.º 4
0
        private void SaveSettings(Uri url, TransportChannelSettings settings)
        {
            m_url = new Uri(Utils.ReplaceLocalhost(url.ToString()));

            m_settings         = settings;
            m_operationTimeout = settings.Configuration.OperationTimeout;

            // initialize the quotas.
            m_quotas = new TcpChannelQuotas();

            m_quotas.MaxBufferSize         = m_settings.Configuration.MaxBufferSize;
            m_quotas.MaxMessageSize        = m_settings.Configuration.MaxMessageSize;
            m_quotas.ChannelLifetime       = m_settings.Configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = m_settings.Configuration.SecurityTokenLifetime;

            m_quotas.MessageContext = new ServiceMessageContext();

            m_quotas.MessageContext.MaxArrayLength      = m_settings.Configuration.MaxArrayLength;
            m_quotas.MessageContext.MaxByteStringLength = m_settings.Configuration.MaxByteStringLength;
            m_quotas.MessageContext.MaxMessageSize      = m_settings.Configuration.MaxMessageSize;
            m_quotas.MessageContext.MaxStringLength     = m_settings.Configuration.MaxStringLength;
            m_quotas.MessageContext.NamespaceUris       = m_settings.NamespaceUris;
            m_quotas.MessageContext.ServerUris          = new StringTable();
            m_quotas.MessageContext.Factory             = m_settings.Factory;

            m_quotas.CertificateValidator = settings.CertificateValidator;
        }
        /// <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);
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Attaches the object to an existing socket.
 /// </summary>
 public TcpServerChannel(
     string                        contextId,
     UaTcpChannelListener          listener,
     BufferManager                 bufferManager, 
     TcpChannelQuotas              quotas,
     X509Certificate2              serverCertificate, 
     EndpointDescriptionCollection endpoints)
 :
     base(contextId, bufferManager, quotas, serverCertificate, endpoints, MessageSecurityMode.None, SecurityPolicies.None)
 {
     m_listener = listener;
     m_queuedResponses = new SortedDictionary<uint,IServiceResponse>();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Attaches the object to an existing socket.
 /// </summary>
 public TcpServerChannel(
     string contextId,
     UaTcpChannelListener listener,
     BufferManager bufferManager,
     TcpChannelQuotas quotas,
     X509Certificate2 serverCertificate,
     EndpointDescriptionCollection endpoints)
     :
     base(contextId, bufferManager, quotas, serverCertificate, endpoints, MessageSecurityMode.None, SecurityPolicies.None)
 {
     m_listener        = listener;
     m_queuedResponses = new SortedDictionary <uint, IServiceResponse>();
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes the request channel for use as a subtype.
        /// </summary>
        protected UaTcpRequestChannel(
            ChannelManagerBase manager,
            string factoryId,
            EndpointAddress address,
            Uri via,
            TcpChannelQuotas quotas)
            :
            base(manager)
        {
            m_factoryId = factoryId;
            m_address   = address;
            m_via       = via;
            m_quotas    = quotas;

            m_ResponseCallack = new AsyncCallback(OnResponse);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a channel for for a client.
        /// </summary>
        public TcpClientChannel(
            string              contextId,
            BufferManager       bufferManager, 
            TcpChannelQuotas    quotas,
            X509Certificate2    clientCertificate,        
            X509Certificate2    serverCertificate,  
            EndpointDescription endpoint)
        :
            base(
                contextId,
                bufferManager, 
                quotas, 
                serverCertificate, 
                (endpoint != null)?new EndpointDescriptionCollection(new EndpointDescription[] { endpoint }):null,
                (endpoint != null)?endpoint.SecurityMode:MessageSecurityMode.None, 
                (endpoint != null)?endpoint.SecurityPolicyUri:SecurityPolicies.None)
        {
            if (endpoint != null && endpoint.SecurityMode != MessageSecurityMode.None)
            {
                if (clientCertificate == null) throw new ArgumentNullException("clientCertificate");
                
                if (clientCertificate.RawData.Length > TcpMessageLimits.MaxCertificateSize)
                {
                    throw new ArgumentException(
                        Utils.Format("The DER encoded certificate may not be more than {0} bytes.", TcpMessageLimits.MaxCertificateSize), 
                        "clientCertificate");
                }

                ClientCertificate = clientCertificate;
            }

            m_requests = new Dictionary<uint,WriteOperation>();
            m_lastRequestId = 0;
            m_ConnectCallback = new AsyncCallback(OnConnectComplete);
            m_StartHandshake = new TimerCallback(OnScheduledHandshake);
            m_HandshakeComplete = new AsyncCallback(OnHandshakeComplete);

            // save the endpoint.
            EndpointDescription = endpoint;
            m_url = new Uri(endpoint.EndpointUrl);
        }
        /// <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;
                }
            }
        }
Ejemplo n.º 11
0
        internal UaTcpReplyChannel(
            ChannelManagerBase manager,
            string listenerId,
            EndpointAddress address,
            TcpServerChannel channel,
            TcpChannelQuotas quotas)
            :
            base(manager)
        {
            m_listenerId = listenerId;
            m_address    = address;
            m_channel    = channel;
            m_quotas     = quotas;

            m_requestQueue   = new Queue <RequestContext>();
            m_operationQueue = new Queue <TcpAsyncOperation <RequestContext> >();

            m_RequestReceivedCallback = new TcpChannelRequestEventHandler(OnRequestReceived);

            // register for notifications.
            m_channel.SetRequestReceivedCallback(m_RequestReceivedCallback);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Attaches the object to an existing socket.
        /// </summary>
        public TcpChannel(
            string contextId,
            BufferManager bufferManager,
            TcpChannelQuotas quotas,
            X509Certificate2 serverCertificate,
            EndpointDescriptionCollection endpoints,
            MessageSecurityMode securityMode,
            string securityPolicyUri)
        {
            if (bufferManager == null)
            {
                throw new ArgumentNullException("bufferManager");
            }
            if (quotas == null)
            {
                throw new ArgumentNullException("quotas");
            }

            // create a unique contex if none provided.
            m_contextId = contextId;

            if (String.IsNullOrEmpty(m_contextId))
            {
                m_contextId = Guid.NewGuid().ToString();
            }

            // secuirty turned off if message security mode is set to none.
            if (securityMode == MessageSecurityMode.None)
            {
                securityPolicyUri = SecurityPolicies.None;
            }

            if (securityMode != MessageSecurityMode.None)
            {
                if (serverCertificate == null)
                {
                    throw new ArgumentNullException("serverCertificate");
                }

                if (serverCertificate.RawData.Length > TcpMessageLimits.MaxCertificateSize)
                {
                    throw new ArgumentException(
                              Utils.Format("The DER encoded certificate may not be more than {0} bytes.", TcpMessageLimits.MaxCertificateSize),
                              "serverCertificate");
                }
            }

            if (new UTF8Encoding().GetByteCount(securityPolicyUri) > TcpMessageLimits.MaxSecurityPolicyUriSize)
            {
                throw new ArgumentException(
                          Utils.Format("UTF-8 form of the security policy URI may not be more than {0} bytes.", TcpMessageLimits.MaxSecurityPolicyUriSize),
                          "securityPolicyUri");
            }

            m_bufferManager     = bufferManager;
            m_quotas            = quotas;
            m_serverCertificate = serverCertificate;
            m_endpoints         = endpoints;
            m_securityMode      = securityMode;
            m_securityPolicyUri = securityPolicyUri;
            m_discoveryOnly     = false;
            m_uninitialized     = true;

            m_state             = TcpChannelState.Closed;
            m_receiveBufferSize = quotas.MaxBufferSize;
            m_sendBufferSize    = quotas.MaxBufferSize;

            if (m_receiveBufferSize < TcpMessageLimits.MinBufferSize)
            {
                m_receiveBufferSize = TcpMessageLimits.MinBufferSize;
            }

            if (m_receiveBufferSize > TcpMessageLimits.MaxBufferSize)
            {
                m_receiveBufferSize = TcpMessageLimits.MaxBufferSize;
            }

            if (m_sendBufferSize < TcpMessageLimits.MinBufferSize)
            {
                m_sendBufferSize = TcpMessageLimits.MinBufferSize;
            }

            if (m_sendBufferSize > TcpMessageLimits.MaxBufferSize)
            {
                m_sendBufferSize = TcpMessageLimits.MaxBufferSize;
            }

            m_maxRequestMessageSize  = quotas.MaxMessageSize;
            m_maxResponseMessageSize = quotas.MaxMessageSize;

            CalculateSymmetricKeySizes();
        }
        /// <summary>
        /// Opens the listener and starts accepting connection.
        /// </summary>
        /// <param name="baseAddress">The base address.</param>
        /// <param name="settings">The settings to use when creating the listener.</param>
        /// <param name="callback">The callback to use when requests arrive via the channel.</param>
        /// <exception cref="ArgumentNullException">Thrown if any parameter is null.</exception>
        /// <exception cref="ServiceResultException">Thrown if any communication error occurs.</exception>
        public void Open(Uri baseAddress, TransportListenerSettings settings, ITransportListenerCallback callback)
        {
            // assign a unique guid to the listener.
            m_listenerId = Guid.NewGuid().ToString();

            m_uri = baseAddress;
            m_descriptions = settings.Descriptions;
            m_configuration = settings.Configuration;

            // initialize the quotas.
            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 = new ServiceMessageContext();

            m_quotas.MessageContext.MaxArrayLength = m_configuration.MaxArrayLength;
            m_quotas.MessageContext.MaxByteStringLength = m_configuration.MaxByteStringLength;
            m_quotas.MessageContext.MaxMessageSize = m_configuration.MaxMessageSize;
            m_quotas.MessageContext.MaxStringLength = m_configuration.MaxStringLength;
            m_quotas.MessageContext.NamespaceUris = settings.NamespaceUris;
            m_quotas.MessageContext.ServerUris = new StringTable();
            m_quotas.MessageContext.Factory = settings.Factory;

            m_quotas.CertificateValidator = settings.CertificateValidator;

            // save the callback to the server.
            m_callback = callback;

            m_serverCert = settings.ServerCertificate;

            // start the listener
            Start();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Saves the settings so the channel can be opened later.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="settings">The settings.</param>
        private void SaveSettings(Uri url, TransportChannelSettings settings)
        {
            // save the settings.
            m_url = url;
            m_settings = settings;
            m_operationTimeout = settings.Configuration.OperationTimeout;

            // initialize the quotas.
            m_quotas = new TcpChannelQuotas();

            m_quotas.MaxBufferSize = m_settings.Configuration.MaxBufferSize;
            m_quotas.MaxMessageSize = m_settings.Configuration.MaxMessageSize;
            m_quotas.ChannelLifetime = m_settings.Configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = m_settings.Configuration.SecurityTokenLifetime;

            m_quotas.MessageContext = new ServiceMessageContext();

            m_quotas.MessageContext.MaxArrayLength = m_settings.Configuration.MaxArrayLength;
            m_quotas.MessageContext.MaxByteStringLength = m_settings.Configuration.MaxByteStringLength;
            m_quotas.MessageContext.MaxMessageSize = m_settings.Configuration.MaxMessageSize;
            m_quotas.MessageContext.MaxStringLength = m_settings.Configuration.MaxStringLength;
            m_quotas.MessageContext.NamespaceUris = m_settings.NamespaceUris;
            m_quotas.MessageContext.ServerUris = new StringTable();
            m_quotas.MessageContext.Factory = m_settings.Factory;

            m_quotas.CertificateValidator = settings.CertificateValidator;

            // create the buffer manager.
            m_bufferManager = new BufferManager("Client", (int)Int32.MaxValue, settings.Configuration.MaxBufferSize);
        }
        private void SaveSettings(Uri url, TransportChannelSettings settings)
        {
            m_url = new Uri(Utils.ReplaceLocalhost(url.ToString()));

            m_settings = settings;
            m_operationTimeout = settings.Configuration.OperationTimeout;

            // initialize the quotas.
            m_quotas = new TcpChannelQuotas();

            m_quotas.MaxBufferSize = m_settings.Configuration.MaxBufferSize;
            m_quotas.MaxMessageSize = m_settings.Configuration.MaxMessageSize;
            m_quotas.ChannelLifetime = m_settings.Configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = m_settings.Configuration.SecurityTokenLifetime;

            m_quotas.MessageContext = new ServiceMessageContext();

            m_quotas.MessageContext.MaxArrayLength = m_settings.Configuration.MaxArrayLength;
            m_quotas.MessageContext.MaxByteStringLength = m_settings.Configuration.MaxByteStringLength;
            m_quotas.MessageContext.MaxMessageSize = m_settings.Configuration.MaxMessageSize;
            m_quotas.MessageContext.MaxStringLength = m_settings.Configuration.MaxStringLength;
            m_quotas.MessageContext.NamespaceUris = m_settings.NamespaceUris;
            m_quotas.MessageContext.ServerUris = new StringTable();
            m_quotas.MessageContext.Factory = m_settings.Factory;

            m_quotas.CertificateValidator = settings.CertificateValidator;
        }