コード例 #1
0
        /// <summary>
        /// Loads the binding's settings from a XML encoded string.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentException">Thrown if the settings are not valid.</exception>
        private void LoadSettings(NetTcpBinding binding, string settings)
        {
            if (string.IsNullOrWhiteSpace(settings))
            {
                return;
            }

            LillTek.Xml.XmlNode root = LillTek.Xml.XmlNode.Parse(settings);

            if (root.Name != "netTcpBinding")
            {
                throw new ArgumentException("<netTcpBinding> XML element expected for NetTcpBinding configuration settings.");
            }

            try
            {
                // Parse the basic properties

                binding.CloseTimeout           = Serialize.Parse(root["/closeTimeout"], binding.CloseTimeout);
                binding.HostNameComparisonMode = Serialize.Parse <HostNameComparisonMode>(root["/hostNameComparisonMode"], binding.HostNameComparisonMode);
                binding.ListenBacklog          = Serialize.Parse(root["/listenBacklog"], binding.ListenBacklog);
                binding.MaxBufferPoolSize      = Serialize.Parse(root["/maxBufferPoolSize"], binding.MaxBufferPoolSize);
                binding.MaxBufferSize          = Serialize.Parse(root["/maxBufferSize"], binding.MaxBufferSize);
                binding.MaxConnections         = Serialize.Parse(root["/maxConnections"], binding.MaxConnections);
                binding.MaxReceivedMessageSize = Serialize.Parse(root["/maxReceivedMessageSize"], binding.MaxReceivedMessageSize);
                binding.Name                = Serialize.Parse(root["/name"], binding.Name);
                binding.Namespace           = Serialize.Parse(root["/namespace"], binding.Namespace);
                binding.OpenTimeout         = Serialize.Parse(root["/openTimeout"], binding.OpenTimeout);
                binding.PortSharingEnabled  = Serialize.Parse(root["/portSharingEnabled"], binding.PortSharingEnabled);
                binding.ReceiveTimeout      = Serialize.Parse(root["/receiveTimeout"], binding.ReceiveTimeout);
                binding.SendTimeout         = Serialize.Parse(root["/sendTimeout"], binding.SendTimeout);
                binding.TransactionFlow     = Serialize.Parse(root["/transactionFlow"], binding.TransactionFlow);
                binding.TransactionProtocol = Parse(root["/transactionProtocol"], binding.TransactionProtocol);
                binding.TransferMode        = Serialize.Parse <TransferMode>(root["/transferMode"], binding.TransferMode);

                // Parse the reader quotas

                Parse(binding.ReaderQuotas, root);

                // Parse the reliable session settings

                binding.ReliableSession.Enabled           = Serialize.Parse(root["/reliableSession/enabled"], binding.ReliableSession.Enabled);
                binding.ReliableSession.InactivityTimeout = Serialize.Parse(root["/reliableSession/inactivityTimeout"], binding.ReliableSession.InactivityTimeout);
                binding.ReliableSession.Ordered           = Serialize.Parse(root["/reliableSession/ordered"], binding.ReliableSession.Ordered);

                // Parse the Security settings

                binding.Security.Message.AlgorithmSuite       = Parse(root["/security/message/algorithmSuite"], binding.Security.Message.AlgorithmSuite);
                binding.Security.Message.ClientCredentialType = Serialize.Parse <MessageCredentialType>(root["/security/message/clientCredentialType"], binding.Security.Message.ClientCredentialType);

                binding.Security.Mode = Serialize.Parse <SecurityMode>(root["/security/mode"], binding.Security.Mode);

                binding.Security.Transport.ClientCredentialType = Serialize.Parse <TcpClientCredentialType>(root["/security/transport/clientCredentialType"], binding.Security.Transport.ClientCredentialType);
                binding.Security.Transport.ProtectionLevel      = Serialize.Parse <ProtectionLevel>(root["/security/transport/protectionLevel"], binding.Security.Transport.ProtectionLevel);
            }
            catch (Exception e)
            {
                throw new ArgumentException("Error parsing WcfEndpoint settings: " + e.Message, e);
            }
        }
コード例 #2
0
 private void Parse(XmlDictionaryReaderQuotas readerQuotas, LillTek.Xml.XmlNode root)
 {
     readerQuotas.MaxArrayLength         = Serialize.Parse(root["/readerQuotas/maxArrayLength"], readerQuotas.MaxArrayLength);
     readerQuotas.MaxBytesPerRead        = Serialize.Parse(root["/readerQuotas/maxBytesPerRead"], readerQuotas.MaxBytesPerRead);
     readerQuotas.MaxDepth               = Serialize.Parse(root["/readerQuotas/maxDepth"], readerQuotas.MaxDepth);
     readerQuotas.MaxNameTableCharCount  = Serialize.Parse(root["/readerQuotas/maxNameTableCharCount"], readerQuotas.MaxNameTableCharCount);
     readerQuotas.MaxStringContentLength = Serialize.Parse(root["/readerQuotas/maxStringContentLength"], readerQuotas.MaxStringContentLength);
 }
コード例 #3
0
        /// <summary>
        /// Loads the binding's security settings from a XML encoded string.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentException">Thrown if the settings are not valid.</exception>
        private void LoadSettings(BasicHttpBinding binding, string settings)
        {
            if (string.IsNullOrWhiteSpace(settings))
            {
                return;
            }

            LillTek.Xml.XmlNode root = LillTek.Xml.XmlNode.Parse(settings);

            if (root.Name != "basicHttpBinding")
            {
                throw new ArgumentException("<basicHttpBinding> XML element expected for BasicHttpBinding configuration settings.");
            }

            try
            {
                // Parse the basic properties

                binding.AllowCookies           = Serialize.Parse(root["/allowCookies"], binding.AllowCookies);
                binding.BypassProxyOnLocal     = Serialize.Parse(root["/bypassProxyOnLocal"], binding.BypassProxyOnLocal);
                binding.CloseTimeout           = Serialize.Parse(root["/closeTimeout"], binding.CloseTimeout);
                binding.HostNameComparisonMode = Serialize.Parse <HostNameComparisonMode>(root["/hostNameComparisonMode"], binding.HostNameComparisonMode);
                binding.MaxBufferPoolSize      = Serialize.Parse(root["/maxBufferPoolSize"], binding.MaxBufferPoolSize);
                binding.MaxBufferSize          = Serialize.Parse(root["/maxBufferSize"], binding.MaxBufferSize);
                binding.MaxReceivedMessageSize = Serialize.Parse(root["/maxReceivedMessageSize"], binding.MaxReceivedMessageSize);
                binding.MessageEncoding        = Serialize.Parse <WSMessageEncoding>(root["/messageEncoding"], binding.MessageEncoding);
                binding.Name               = Serialize.Parse(root["/name"], binding.Name);
                binding.Namespace          = Serialize.Parse(root["/namespace"], binding.Namespace);
                binding.OpenTimeout        = Serialize.Parse(root["/openTimeout"], binding.OpenTimeout);
                binding.ProxyAddress       = Serialize.Parse(root["/proxyAddress"], binding.ProxyAddress);
                binding.ReceiveTimeout     = Serialize.Parse(root["/receiveTimeout"], binding.ReceiveTimeout);
                binding.SendTimeout        = Serialize.Parse(root["/sendTimeout"], binding.SendTimeout);
                binding.TextEncoding       = Parse(root["/textEncoding"], binding.TextEncoding);
                binding.TransferMode       = Serialize.Parse <TransferMode>(root["/transferMode"], binding.TransferMode);
                binding.UseDefaultWebProxy = Serialize.Parse(root["/useDefaultWebProxy"], binding.UseDefaultWebProxy);

                // Parse the reader quotas

                Parse(binding.ReaderQuotas, root);

                // Parse the Security settings

                binding.Security.Message.AlgorithmSuite       = Parse(root["/security/message/algorithmSuite"], binding.Security.Message.AlgorithmSuite);
                binding.Security.Message.ClientCredentialType = Serialize.Parse <BasicHttpMessageCredentialType>(root["/security/message/clientCredentialType"], binding.Security.Message.ClientCredentialType);

                binding.Security.Mode = Serialize.Parse <BasicHttpSecurityMode>(root["/security/mode"], binding.Security.Mode);

                binding.Security.Transport.ClientCredentialType = Serialize.Parse <HttpClientCredentialType>(root["/security/transport/clientCredentialType"], binding.Security.Transport.ClientCredentialType);
                binding.Security.Transport.ProxyCredentialType  = Serialize.Parse <HttpProxyCredentialType>(root["/security/transport/proxyCredentialType"], binding.Security.Transport.ProxyCredentialType);
                binding.Security.Transport.Realm = root.GetPropStr("/security/transport/realm", binding.Security.Transport.Realm);
            }
            catch (Exception e)
            {
                throw new ArgumentException("Error parsing WcfEndpoint settings: " + e.Message, e);
            }
        }
コード例 #4
0
        /// <summary>
        /// Loads the binding's settings from a XML encoded string.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentException">Thrown if the settings are not valid.</exception>
        private void LoadSettings(NetNamedPipeBinding binding, string settings)
        {
            if (string.IsNullOrWhiteSpace(settings))
            {
                return;
            }

            LillTek.Xml.XmlNode root = LillTek.Xml.XmlNode.Parse(settings);

            if (root.Name != "netNamedPipeBinding")
            {
                throw new ArgumentException("<netNamedPipeBinding> XML element expected for NetNamedPipeBinding configuration settings.");
            }

            try
            {
                // Parse the basic properties

                binding.CloseTimeout           = Serialize.Parse(root["/closeTimeout"], binding.CloseTimeout);
                binding.HostNameComparisonMode = Serialize.Parse <HostNameComparisonMode>(root["/hostNameComparisonMode"], binding.HostNameComparisonMode);
                binding.MaxBufferPoolSize      = Serialize.Parse(root["/maxBufferPoolSize"], binding.MaxBufferPoolSize);
                binding.MaxBufferSize          = Serialize.Parse(root["/maxBufferSize"], binding.MaxBufferSize);
                binding.MaxConnections         = Serialize.Parse(root["/maxConnections"], binding.MaxConnections);
                binding.MaxReceivedMessageSize = Serialize.Parse(root["/maxReceivedMessageSize"], binding.MaxReceivedMessageSize);
                binding.Name                = Serialize.Parse(root["/name"], binding.Name);
                binding.Namespace           = Serialize.Parse(root["/namespace"], binding.Namespace);
                binding.OpenTimeout         = Serialize.Parse(root["/openTimeout"], binding.OpenTimeout);
                binding.ReceiveTimeout      = Serialize.Parse(root["/receiveTimeout"], binding.ReceiveTimeout);
                binding.SendTimeout         = Serialize.Parse(root["/sendTimeout"], binding.SendTimeout);
                binding.TransactionFlow     = Serialize.Parse(root["/transactionFlow"], binding.TransactionFlow);
                binding.TransactionProtocol = Parse(root["/transactionProtocol"], binding.TransactionProtocol);
                binding.TransferMode        = Serialize.Parse <TransferMode>(root["/transferMode"], binding.TransferMode);

                // Parse the reader quotas

                Parse(binding.ReaderQuotas, root);

                // Parse the Security settings

                binding.Security.Mode = Serialize.Parse <NetNamedPipeSecurityMode>(root["/security/mode"], binding.Security.Mode);

                binding.Security.Transport.ProtectionLevel = Serialize.Parse <ProtectionLevel>(root["/security/transport/protectionLevel"], binding.Security.Transport.ProtectionLevel);
            }
            catch (Exception e)
            {
                throw new ArgumentException("Error parsing WcfEndpoint settings: " + e.Message, e);
            }
        }
コード例 #5
0
        /// <summary>
        /// Parses the service behaviors encoded as XML and applies them to the hosted service.
        /// </summary>
        /// <param name="behaviors">The service behavior XML (or <c>null</c> or an empty string).</param>
        /// <remarks>
        /// <para>
        /// The current implementation supports the parsing of a limited set of possible
        /// service behaviors implemented by WCF.  Support for the other behaviors will be
        /// added in a future release.  Here's the current implementation status:
        /// </para>
        /// <list type="table">
        ///     <item>
        ///         <term><see cref="DataContractSerializer" /></term>
        ///         <description><b>Not Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="PersistenceProvider" /></term>
        ///         <description><b>Not Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="ServiceAuthorizationBehavior" /></term>
        ///         <description><b>Not Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="ServiceCredentials" /></term>
        ///         <description><b>Not Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="ServiceDebugBehavior" /></term>
        ///         <description><b>Not Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="ServiceMetadataBehavior" /></term>
        ///         <description><b>Not Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="ServiceSecurityAuditBehavior" /></term>
        ///         <description><b>Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="ServiceThrottlingBehavior" /></term>
        ///         <description><b>Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="ServiceTimeoutsBehavior" /></term>
        ///         <description><b>Implemented</b></description>
        ///     </item>
        ///     <item>
        ///         <term><see cref="WorkflowRuntimeBehavior" /></term>
        ///         <description><b>Not Implemented</b></description>
        ///     </item>
        /// </list>
        /// <para>
        /// The XML format for a service behavior is the same as found in
        /// standard .NET configuration files.  Here's an example:
        /// </para>
        /// <code language="none">
        /// &lt;behavior&gt;
        ///     &lt;serviceThrottling maxConcurrentCalls="100" /&gt;
        ///     &lt;serviceTimeouts transactionTimeout="00:01:00" /&gt;
        /// &lt;/behavior&gt;
        /// </code>
        /// </remarks>
        public void AddBehaviors(string behaviors)
        {
            if (string.IsNullOrWhiteSpace(behaviors))
            {
                return;
            }

            LillTek.Xml.XmlNode root = LillTek.Xml.XmlNode.Parse(behaviors);

            if (root.Name != "behavior")
            {
                throw new ArgumentException("<behavior> expected as the root XML element.");
            }

            try
            {
                // Default service behavior attributes.

                ServiceBehaviorAttribute serviceBehavior = (ServiceBehaviorAttribute)host.Description.Behaviors[typeof(ServiceBehaviorAttribute)];

                if (serviceBehavior != null)
                {
                    string   sTimeout;
                    TimeSpan timeout;

                    sTimeout = root["/serviceTimeouts/transactionTimeout"];
                    if (sTimeout != null)
                    {
                        timeout = Serialize.Parse(sTimeout, TimeSpan.Zero);
                        if (timeout > TimeSpan.Zero)
                        {
                            serviceBehavior.TransactionTimeout = timeout.ToString();
                        }
                    }
                }

                // ServiceSecurityAudit

                var serviceSecurityAudit = new ServiceSecurityAuditBehavior();

                serviceSecurityAudit.AuditLogLocation = Serialize.Parse <AuditLogLocation>(root["/serviceSecurityAudit/auditLogLocation"], serviceSecurityAudit.AuditLogLocation);
                serviceSecurityAudit.MessageAuthenticationAuditLevel = Serialize.Parse <AuditLevel>(root["/serviceSecurityAudit/messageAuthenticationAuditLevel"], serviceSecurityAudit.MessageAuthenticationAuditLevel);
                serviceSecurityAudit.ServiceAuthorizationAuditLevel  = Serialize.Parse <AuditLevel>(root["/serviceSecurityAudit/serviceAuthorizationAuditLevel"], serviceSecurityAudit.ServiceAuthorizationAuditLevel);
                serviceSecurityAudit.SuppressAuditFailure            = Serialize.Parse(root["/serviceSecurityAudit/suppressAuditFailure"], serviceSecurityAudit.SuppressAuditFailure);

                host.Description.Behaviors.Add(serviceSecurityAudit);

                // ServiceThrottling

                var serviceThrottling = new ServiceThrottlingBehavior();

                serviceThrottling.MaxConcurrentCalls     = Serialize.Parse(root["/serviceThrottling/maxConcurrentCalls"], serviceThrottling.MaxConcurrentCalls);
                serviceThrottling.MaxConcurrentInstances = Serialize.Parse(root["/serviceThrottling/maxConcurrentInstances"], serviceThrottling.MaxConcurrentInstances);
                serviceThrottling.MaxConcurrentSessions  = Serialize.Parse(root["/serviceThrottling/maxConcurrentSessions"], serviceThrottling.MaxConcurrentSessions);

                host.Description.Behaviors.Add(serviceThrottling);

                // Check for unsupported behaviors

                var unsupported = new string[]
                {
                    "dataContractSerializer",
                    "persistenceProvider",
                    "serviceAuthorization",
                    "serviceCredentials",
                    "serviceDebug",
                    "serviceMetadata",
                    "workflowRuntime"
                };

                foreach (string behavior in unsupported)
                {
                    if (root.GetNode(behavior) != null)
                    {
                        throw new NotImplementedException(string.Format("<{0}> behavior parsing is not supported by the LillTek Platform at this time.", behavior));
                    }
                }
            }
            catch (Exception e)
            {
                throw new ArgumentException("Error parsing WcfServiceHost behavior: " + e.Message, e);
            }
        }