Esempio n. 1
0
        void ApplyAuditBehaviorSettings(BindingContext context)
        {
            ServiceSecurityAuditBehavior auditBehavior = context.BindingParameters.Find <ServiceSecurityAuditBehavior>();

            if (auditBehavior != null)
            {
                this.auditBehavior = auditBehavior.Clone();
            }
            else
            {
                this.auditBehavior = new ServiceSecurityAuditBehavior();
            }
        }
Esempio n. 2
0
        protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context, System.ServiceModel.Channels.MessageEncoderFactory defaultMessageEncoderFactory, HostNameComparisonMode hostNameComparisonMode) : base(context.Binding)
        {
            HostNameComparisonModeHelper.Validate(hostNameComparisonMode);
            this.hostNameComparisonMode = hostNameComparisonMode;
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;
            Collection <MessageEncodingBindingElement> collection = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (collection.Count > 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("MultipleMebesInParameters")));
            }
            if (collection.Count == 1)
            {
                this.messageEncoderFactory = collection[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            else
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }
            if (this.messageEncoderFactory != null)
            {
                this.messageVersion = this.messageEncoderFactory.MessageVersion;
            }
            else
            {
                this.messageVersion = System.ServiceModel.Channels.MessageVersion.None;
            }
            ServiceSecurityAuditBehavior behavior = context.BindingParameters.Find <ServiceSecurityAuditBehavior>();

            if (behavior != null)
            {
                this.auditBehavior = behavior.Clone();
            }
            else
            {
                this.auditBehavior = new ServiceSecurityAuditBehavior();
            }
            if ((context.ListenUriMode == ListenUriMode.Unique) && (context.ListenUriBaseAddress == null))
            {
                UriBuilder builder = new UriBuilder(this.Scheme, DnsCache.MachineName)
                {
                    Path = this.GeneratedAddressPrefix
                };
                context.ListenUriBaseAddress = builder.Uri;
            }
            UriSchemeKeyedCollection.ValidateBaseAddress(context.ListenUriBaseAddress, "baseAddress");
            if ((context.ListenUriBaseAddress.Scheme != this.Scheme) && (string.Compare(context.ListenUriBaseAddress.Scheme, this.Scheme, StringComparison.OrdinalIgnoreCase) != 0))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("context.ListenUriBaseAddress", System.ServiceModel.SR.GetString("InvalidUriScheme", new object[] { context.ListenUriBaseAddress.Scheme, this.Scheme }));
            }
            if (context.ListenUriMode == ListenUriMode.Explicit)
            {
                this.SetUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);
            }
            else
            {
                string listenUriRelativeAddress = context.ListenUriRelativeAddress;
                if ((listenUriRelativeAddress.Length > 0) && !listenUriRelativeAddress.EndsWith("/", StringComparison.Ordinal))
                {
                    listenUriRelativeAddress = listenUriRelativeAddress + "/";
                }
                this.SetUri(context.ListenUriBaseAddress, listenUriRelativeAddress + Guid.NewGuid().ToString());
            }
            this.transportManagerContainer = new TransportManagerContainer(this);
        }
        protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context,
                                           MessageEncoderFactory defaultMessageEncoderFactory, HostNameComparisonMode hostNameComparisonMode)
            : base(context.Binding)
        {
            HostNameComparisonModeHelper.Validate(hostNameComparisonMode);
            this.hostNameComparisonMode = hostNameComparisonMode;
            this.manualAddressing       = bindingElement.ManualAddressing;
            this.maxBufferPoolSize      = bindingElement.MaxBufferPoolSize;
            this.maxReceivedMessageSize = bindingElement.MaxReceivedMessageSize;

            Collection <MessageEncodingBindingElement> messageEncoderBindingElements
                = context.BindingParameters.FindAll <MessageEncodingBindingElement>();

            if (messageEncoderBindingElements.Count > 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MultipleMebesInParameters)));
            }
            else if (messageEncoderBindingElements.Count == 1)
            {
                this.messageEncoderFactory = messageEncoderBindingElements[0].CreateMessageEncoderFactory();
                context.BindingParameters.Remove <MessageEncodingBindingElement>();
            }
            else
            {
                this.messageEncoderFactory = defaultMessageEncoderFactory;
            }

            if (null != this.messageEncoderFactory)
            {
                this.messageVersion = this.messageEncoderFactory.MessageVersion;
            }
            else
            {
                this.messageVersion = MessageVersion.None;
            }

            ServiceSecurityAuditBehavior auditBehavior = context.BindingParameters.Find <ServiceSecurityAuditBehavior>();

            if (auditBehavior != null)
            {
                this.auditBehavior = auditBehavior.Clone();
            }
            else
            {
                this.auditBehavior = new ServiceSecurityAuditBehavior();
            }

            if ((context.ListenUriMode == ListenUriMode.Unique) && (context.ListenUriBaseAddress == null))
            {
                UriBuilder uriBuilder = new UriBuilder(this.Scheme, DnsCache.MachineName);
                uriBuilder.Path = this.GeneratedAddressPrefix;
                context.ListenUriBaseAddress = uriBuilder.Uri;
            }

            UriSchemeKeyedCollection.ValidateBaseAddress(context.ListenUriBaseAddress, "baseAddress");
            if (context.ListenUriBaseAddress.Scheme != this.Scheme)
            {
                // URI schemes are case-insensitive, so try a case insensitive compare now
                if (string.Compare(context.ListenUriBaseAddress.Scheme, this.Scheme, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
                              "context.ListenUriBaseAddress",
                              SR.GetString(SR.InvalidUriScheme, context.ListenUriBaseAddress.Scheme, this.Scheme));
                }
            }

            Fx.Assert(context.ListenUriRelativeAddress != null, ""); // validated by BindingContext
            if (context.ListenUriMode == ListenUriMode.Explicit)
            {
                this.SetUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);
            }
            else // ListenUriMode.Unique:
            {
                string relativeAddress = context.ListenUriRelativeAddress;
                if (relativeAddress.Length > 0 && !relativeAddress.EndsWith("/", StringComparison.Ordinal))
                {
                    relativeAddress += "/";
                }

                this.SetUri(context.ListenUriBaseAddress, relativeAddress + Guid.NewGuid().ToString());
            }

            this.transportManagerContainer = new TransportManagerContainer(this);
        }