Exemple #1
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);
        }
Exemple #2
0
        protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context,
                                           MessageEncoderFactory defaultMessageEncoderFactory, HostNameComparisonMode hostNameComparisonMode)
            : base(context.Binding)
        {
            HostNameComparisonModeHelper.Validate(hostNameComparisonMode);
            this.hostNameComparisonMode = hostNameComparisonMode;
            manualAddressing            = bindingElement.ManualAddressing;
            maxBufferPoolSize           = bindingElement.MaxBufferPoolSize;
            maxReceivedMessageSize      = bindingElement.MaxReceivedMessageSize;

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

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

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

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

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

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

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

            transportManagerContainer = new TransportManagerContainer(this);
        }