コード例 #1
0
        public override IServiceDispatcher BuildServiceDispatcher <TChannel>(BindingContext context, IServiceDispatcher innerDispatcher)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
            }

            if (!CanBuildServiceDispatcher <TChannel>(context))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.ChannelTypeNotSupported, typeof(TChannel)), "TChannel"));
            }

            ReaderQuotas = context.GetInnerProperty <XmlDictionaryReaderQuotas>();
            if (ReaderQuotas == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.EncodingBindingElementDoesNotHandleReaderQuotas)));
            }

            TransportBindingElement transportBindingElement = null;

            if (context.RemainingBindingElements != null)
            {
                transportBindingElement = context.RemainingBindingElements.Find <TransportBindingElement>();
            }

            if (transportBindingElement != null)
            {
                MaxReceivedMessageSize = transportBindingElement.MaxReceivedMessageSize;
            }

            return(BuildServiceDispatcherCore <TChannel>(context, innerDispatcher));
        }
コード例 #2
0
        void SetMaxReceivedMessageSizeFromTransport(BindingContext context)
        {
            TransportBindingElement transport = context.Binding.Elements.Find <TransportBindingElement>();

            if (transport != null)
            {
                // We are guaranteed that a transport exists when building a binding;
                // Allow the regular flow/checks to happen rather than throw here
                // (InternalBuildChannelListener will call into the BindingContext. Validation happens there and it will throw)
                maxReceivedMessageSize = transport.MaxReceivedMessageSize;
            }
        }
コード例 #3
0
ファイル: Binding.cs プロジェクト: willaimyou/CoreWCF
        internal void EnsureInvariants(string contractName)
        {
            BindingElementCollection elements  = CreateBindingElements();
            TransportBindingElement  transport = null;
            int index;

            for (index = 0; index < elements.Count; index++)
            {
                transport = elements[index] as TransportBindingElement;
                if (transport != null)
                {
                    break;
                }
            }

            if (transport == null)
            {
                if (contractName == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR.Format(SR.CustomBindingRequiresTransport, Name)));
                }
                else
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                  SR.Format(SR.SFxCustomBindingNeedsTransport1, contractName)));
                }
            }
            if (index != elements.Count - 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.Format(SR.TransportBindingElementMustBeLast, Name, transport.GetType().Name)));
            }
            if (string.IsNullOrEmpty(transport.Scheme))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.Format(SR.InvalidBindingScheme, transport.GetType().Name)));
            }

            if (MessageVersion == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                              SR.Format(SR.MessageVersionMissingFromBinding, Name)));
            }
        }
コード例 #4
0
        private static BindingContext CreateIssuerBindingContextForNegotiation(BindingContext issuerBindingContext)
        {
            TransportBindingElement transport = issuerBindingContext.RemainingBindingElements.Find <TransportBindingElement>();

            if (transport == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.TransportBindingElementNotFound)));
            }
            //ChannelDemuxerBindingElement demuxer = null;
            //// pick the demuxer above transport (i.e. the last demuxer in the array)
            //for (int i = 0; i < issuerBindingContext.RemainingBindingElements.Count; ++i)
            //{
            //    if (issuerBindingContext.RemainingBindingElements[i] is ChannelDemuxerBindingElement)
            //    {
            //        demuxer = (ChannelDemuxerBindingElement)issuerBindingContext.RemainingBindingElements[i];
            //    }
            //}
            //if (demuxer == null)
            //{
            //    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ChannelDemuxerBindingElementNotFound)));
            //}
            BindingElementCollection negotiationBindingElements = new BindingElementCollection
            {
                //negotiationBindingElements.Add(demuxer.Clone());
                transport.Clone()
            };
            CustomBinding binding = new CustomBinding(negotiationBindingElements)
            {
                OpenTimeout    = issuerBindingContext.Binding.OpenTimeout,
                CloseTimeout   = issuerBindingContext.Binding.CloseTimeout,
                SendTimeout    = issuerBindingContext.Binding.SendTimeout,
                ReceiveTimeout = issuerBindingContext.Binding.ReceiveTimeout
            };

            if (issuerBindingContext.ListenUriBaseAddress != null)
            {
                return(new BindingContext(binding, new BindingParameterCollection(issuerBindingContext.BindingParameters), issuerBindingContext.ListenUriBaseAddress,
                                          issuerBindingContext.ListenUriRelativeAddress));//, issuerBindingContext.ListenUriMode);
            }
            else
            {
                return(new BindingContext(binding, new BindingParameterCollection(issuerBindingContext.BindingParameters)));
            }
        }
コード例 #5
0
        protected override bool IsMatch(BindingElement b)
        {
            if (b == null)
            {
                return(false);
            }
            TransportBindingElement transport = b as TransportBindingElement;

            if (transport == null)
            {
                return(false);
            }
            if (maxBufferPoolSize != transport.MaxBufferPoolSize)
            {
                return(false);
            }
            if (maxReceivedMessageSize != transport.MaxReceivedMessageSize)
            {
                return(false);
            }
            return(true);
        }
コード例 #6
0
 protected TransportBindingElement(TransportBindingElement elementToBeCloned)
 {
     manualAddressing       = elementToBeCloned.manualAddressing;
     maxBufferPoolSize      = elementToBeCloned.maxBufferPoolSize;
     maxReceivedMessageSize = elementToBeCloned.maxReceivedMessageSize;
 }
コード例 #7
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);
        }
コード例 #8
0
 protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context,
                                    HostNameComparisonMode hostNameComparisonMode)
     : this(bindingElement, context, TransportDefaults.GetDefaultMessageEncoderFactory(), hostNameComparisonMode)
 {
 }
コード例 #9
0
 protected TransportChannelListener(TransportBindingElement bindingElement, BindingContext context)
     : this(bindingElement, context, TransportDefaults.GetDefaultMessageEncoderFactory())
 {
 }