public override bool CanBuildChannelListener <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            IAnonymousUriPrefixMatcher anonymousUriPrefixMatcher
                = context.GetInnerProperty <IAnonymousUriPrefixMatcher>();

            if (anonymousUriPrefixMatcher == null)
            {
                return(false);
            }

            MessageVersion message = context.GetInnerProperty <MessageVersion>();

            if (message.Addressing == AddressingVersion.None)
            {
                return(false);
            }

            if (typeof(TChannel) == typeof(IDuplexChannel))
            {
                return(context.CanBuildInnerChannelListener <IReplyChannel>());
            }

            if (typeof(TChannel) == typeof(IDuplexSessionChannel))
            {
                return(context.CanBuildInnerChannelListener <IReplySessionChannel>());
            }

            return(false);
        }
Пример #2
0
 public override bool CanBuildChannelFactory <TChannel> (BindingContext bc)
 {
     Assert.AreEqual(1, bc.Clone().RemainingBindingElements.Count, "#i1");
     Assert.IsNull(bc.GetInnerProperty <MessageEncodingBindingElement> (), "#i2");
     Assert.IsNull(bc.GetInnerProperty <MessageEncoder> (), "#i3");
     Assert.IsNull(bc.GetInnerProperty <MessageEncoderFactory> (), "#i4");
     Assert.AreEqual(1, bc.RemainingBindingElements.Count, "#i5");
     Assert.IsTrue(bc.RemainingBindingElements [0] is HttpTransportBindingElement, "#i6");
     Assert.AreEqual(3, bc.Binding.CreateBindingElements().Count, "#i7");
     return(base.CanBuildChannelFactory <TChannel> (bc));
 }
Пример #3
0
            public override T GetProperty <T>(BindingContext context) where T : class
            {
                if (!(typeof(T) == typeof(ISecurityCapabilities)))
                {
                    return(context.GetInnerProperty <T>());
                }
                ISecurityCapabilities innerProperty = context.GetInnerProperty <ISecurityCapabilities>();

                if (innerProperty != null)
                {
                    return((T) new SecurityCapabilities(innerProperty.SupportsClientAuthentication, true, innerProperty.SupportsClientWindowsIdentity, innerProperty.SupportedRequestProtectionLevel, innerProperty.SupportedRequestProtectionLevel));
                }
                return(default(T));
            }
        public override T GetProperty <T>(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (typeof(T) == typeof(ChannelProtectionRequirements))
            {
                ChannelProtectionRequirements myRequirements = this.GetProtectionRequirements();
                myRequirements.Add(context.GetInnerProperty <ChannelProtectionRequirements>() ?? new ChannelProtectionRequirements());
                return((T)(object)myRequirements);
            }

            return(context.GetInnerProperty <T>());
        }
        public override bool CanBuildChannelFactory <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            MessageVersion message = context.GetInnerProperty <MessageVersion>();

            if (message.Addressing == AddressingVersion.None)
            {
                return(false);
            }

            if (typeof(TChannel) == typeof(IDuplexChannel))
            {
                return(context.CanBuildInnerChannelFactory <IRequestChannel>());
            }

            if (typeof(TChannel) == typeof(IDuplexSessionChannel))
            {
                return(context.CanBuildInnerChannelFactory <IRequestSessionChannel>());
            }

            return(false);
        }
        public override IChannelFactory <TChannel> BuildChannelFactory <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            MessageVersion message = context.GetInnerProperty <MessageVersion>();

            if (message.Addressing == AddressingVersion.None)
            {
                throw new ArgumentException(ExceptionMessages.WsmcRequiresAddressing);
            }

            if (typeof(TChannel) == typeof(IDuplexChannel))
            {
                return((IChannelFactory <TChannel>)(object) new MakeConnectionChannelFactory <IDuplexChannel, IRequestChannel>(new MakeConnectionBindingElement(this), context));
            }

            if (typeof(TChannel) == typeof(IDuplexSessionChannel))
            {
                return((IChannelFactory <TChannel>)(object) new MakeConnectionChannelFactory <IDuplexSessionChannel, IRequestSessionChannel>(new MakeConnectionBindingElement(this), context));
            }

            throw new ArgumentException(String.Format(ExceptionMessages.ChannelTypeNotSupported, (typeof(TChannel))));
        }
Пример #7
0
	public override T GetProperty<T> (BindingContext context)
	{
Console.WriteLine (context.BindingParameters.Count);
foreach (object o in context.BindingParameters) Console.WriteLine (o.GetType ());
		return context.GetInnerProperty<T> ();
		//throw new NotImplementedException ();
	}
Пример #8
0
 public override T GetProperty <T>(BindingContext context)
 {
     if (manager is T)
     {
         return((T)(object)manager);
     }
     return(context.GetInnerProperty <T>());
 }
Пример #9
0
 public override T GetProperty <T>(BindingContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     return(context.GetInnerProperty <T>());
 }
Пример #10
0
 // Token: 0x0600029D RID: 669 RVA: 0x0001222D File Offset: 0x0001042D
 public override T GetProperty <T>(BindingContext context)
 {
     if (typeof(T) == typeof(ISecurityCapabilities))
     {
         return((T)((object)new AutodiscoverSecurityBindingElement.SecurityCapabilities()));
     }
     return(context.GetInnerProperty <T>());
 }
 public override T GetProperty <T>(BindingContext context) where T : class
 {
     if (typeof(T) == typeof(ISecurityCapabilities))
     {
         return(this.authenticator.BootstrapSecurityBindingElement.GetProperty <ISecurityCapabilities>(context));
     }
     return(context.GetInnerProperty <T>());
 }
    public override T GetProperty <T>(BindingContext context)
    {
        if (typeof(T) == typeof(ChannelMessageInterceptor))
        {
            return((T)(object)this.Interceptor);
        }

        return(context.GetInnerProperty <T>());
    }
        public override T GetProperty <T>(BindingContext context)
        {
            if (typeof(T) == typeof(ContextType))
            {
                return((T)(object)this.ContextType);
            }

            return(context.GetInnerProperty <T>());
        }
Пример #14
0
 void Snippet14()
 {
     // <Snippet14>
     CustomBinding binding              = new CustomBinding();
     BindingParameterCollection bpCol   = new BindingParameterCollection();
     BindingContext             context = new BindingContext(binding, bpCol);
     XmlDictionaryReaderQuotas  quotas  = context.GetInnerProperty <XmlDictionaryReaderQuotas>();
     // </Snippet14>
 }
Пример #15
0
        public override T GetProperty <T>(BindingContext context)
        {
            if (typeof(T) == typeof(IReceiveContextSettings))
            {
                return((T)(object)this.httpAcknowledgementSettings);
            }

            return(context.GetInnerProperty <T>());
        }
 public override T GetProperty <T>(BindingContext context)
     where T : class
 {
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
     return(context.GetInnerProperty <T>());
 }
 public override T GetProperty <T>(BindingContext context)
 {
     if (typeof(T) == typeof(IBindingMulticastCapabilities))
     {
         return((T)(object)this);
     }
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     return(context.GetInnerProperty <T>());
 }
Пример #18
0
        public override T GetProperty <T>(BindingContext context)
        {
            // GetProperty<T>(BindingContext context) of SignatureCaseBindingElement must match GetProperty<T>() of SignatureCaseChannelFactory.
            // In runtime, Wcf verifies that the security capabilities the factory claims it can support are also supported by the actual channel.
            // SignatureCaseChannelFactory uses the default implementation of GetProperty<T>() which returns null and this method returns an instance of type ISecurityCapabilities (created by HttpsTransportBindingElement). This makes the WCF throw an exception.
            // Either side could be changed to match the other but setting null here has been chosen because SecurityCapabilities is internal to the .Net Framework. The alternative would have been to copy/paste SecurityCapabilities and create my own implementation of ISecurityCapabilities and override GetProperty<T>() in SignatureCaseChannelFactory.
            // Downside of this is that above protocol channels are not able to read the ISecurityCapabilities.
            if (typeof(T) == typeof(ISecurityCapabilities))
            {
                return(null);
            }

            return(context.GetInnerProperty <T>());
        }
Пример #19
0
        /// <summary>
        /// Returns the property associated with the binding element.
        /// </summary>
        public override T GetProperty <T>(BindingContext context)
        {
            if (typeof(T) == typeof(MessageVersion))
            {
                return((T)(object)MessageVersion.Soap12WSAddressing10);
            }

            if (typeof(T) == typeof(ISecurityCapabilities))
            {
                return((T)(object)new Opc.Ua.Bindings.SecurityCapabilities());
            }

            return(context.GetInnerProperty <T>());
        }
        internal IChannelListener <TChannel> BuildNegotiationChannelListener <TChannel>(BindingContext context)
            where TChannel : class, IChannel
        {
            SecurityCredentialsManager securityCredentials = this.IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>();

            if (securityCredentials == null)
            {
                securityCredentials = ServiceCredentials.CreateDefaultCredentials();
            }

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

            TransportBindingElement transportBindingElement = context.RemainingBindingElements.Find <TransportBindingElement>();

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

            SecurityProtocolFactory        securityProtocolFactory = this.bootstrapSecurityBindingElement.CreateSecurityProtocolFactory <TChannel>(this.IssuerBindingContext.Clone(), securityCredentials, true, this.IssuerBindingContext.Clone());
            MessageSecurityProtocolFactory soapBindingFactory      = securityProtocolFactory as MessageSecurityProtocolFactory;

            if (soapBindingFactory != null)
            {
                soapBindingFactory.ApplyConfidentiality             = soapBindingFactory.ApplyIntegrity
                                                                    = soapBindingFactory.RequireConfidentiality = soapBindingFactory.RequireIntegrity = true;
                MessagePartSpecification bodyPart = new MessagePartSpecification(true);
                soapBindingFactory.ProtectionRequirements.OutgoingSignatureParts.AddParts(bodyPart, RequestSecurityTokenResponseAction);
                soapBindingFactory.ProtectionRequirements.OutgoingEncryptionParts.AddParts(bodyPart, RequestSecurityTokenResponseAction);
                soapBindingFactory.ProtectionRequirements.IncomingSignatureParts.AddParts(bodyPart, RequestSecurityTokenAction);
                soapBindingFactory.ProtectionRequirements.IncomingEncryptionParts.AddParts(bodyPart, RequestSecurityTokenAction);
            }

            SecurityChannelListener <TChannel> securityChannelListener =
                new SecurityChannelListener <TChannel>(this.bootstrapSecurityBindingElement, context);

            securityChannelListener.SecurityProtocolFactory = securityProtocolFactory;
            // do not send back unsecured faults over composite duplex
            securityChannelListener.SendUnsecuredFaults = !SecurityUtils.IsCompositeDuplexBinding(context);

            ChannelBuilder channelBuilder = new ChannelBuilder(context, true);

            securityChannelListener.InitializeListener(channelBuilder);
            this.shouldMatchRstWithEndpointFilter = SecurityUtils.ShouldMatchRstWithEndpointFilter(this.bootstrapSecurityBindingElement);
            return(securityChannelListener);
        }
Пример #21
0
 public override T GetProperty <T>(BindingContext context)
 {
     // augment the context with cached binding parameters
     if (_cacheContextState && _cachedContextState.IsStateCached)
     {
         for (int i = 0; i < _cachedContextState.CachedBindingParameters.Count; ++i)
         {
             if (!context.BindingParameters.Contains(_cachedContextState.CachedBindingParameters[i].GetType()))
             {
                 context.BindingParameters.Add(_cachedContextState.CachedBindingParameters[i]);
             }
         }
     }
     return(context.GetInnerProperty <T>());
 }
 public override T GetProperty <T>(BindingContext context)
 {
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
     if (typeof(T) == typeof(MessageVersion))
     {
         return((T)(object)this.MessageVersion);
     }
     else
     {
         return(context.GetInnerProperty <T>());
     }
 }
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            IAnonymousUriPrefixMatcher anonymousUriPrefixMatcher
                = context.GetInnerProperty <IAnonymousUriPrefixMatcher>();

            if (anonymousUriPrefixMatcher == null)
            {
                throw new Exception(ExceptionMessages.IAnonymousUriPrefixMatcherPropertyNotFound);
            }
            anonymousUriPrefixMatcher.Register(new Uri(MakeConnectionConstants.AnonymousUriTemplate));

            MessageVersion message = context.GetInnerProperty <MessageVersion>();

            if (message.Addressing == AddressingVersion.None)
            {
                throw new ArgumentException(ExceptionMessages.WsmcRequiresAddressing);
            }

            if (typeof(TChannel) == typeof(IDuplexChannel))
            {
                return((IChannelListener <TChannel>)(object) new MakeConnectionChannelListener <IDuplexChannel, IReplyChannel>(new MakeConnectionBindingElement(this), context));
            }

            if (typeof(TChannel) == typeof(IDuplexSessionChannel))
            {
                return((IChannelListener <TChannel>)(object) new MakeConnectionChannelListener <IDuplexSessionChannel, IReplySessionChannel>(new MakeConnectionBindingElement(this), context));
            }

            throw new ArgumentException(String.Format
                                            (ExceptionMessages.ChannelTypeNotSupported, typeof(TChannel)));
        }
Пример #24
0
        public override T GetProperty <T>(BindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (typeof(T) == typeof(MessageVersion))
            {
                return((T)(object)MessageVersion.Default);
            }


            return(context.GetInnerProperty <T>());
        }
Пример #25
0
        public override T GetProperty <T>(BindingContext context)
            where T : class
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (typeof(T) != typeof(ChannelProtectionRequirements))
            {
                return(base.GetProperty <T>(context));
            }
            ChannelProtectionRequirements protectionRequirements = RelayedOnewayTransportBindingElement.GetProtectionRequirements(context);

            protectionRequirements.Add(context.GetInnerProperty <ChannelProtectionRequirements>() ?? new ChannelProtectionRequirements());
            return((T)protectionRequirements);
        }
Пример #26
0
        public void GetInnerPropertyIsNothingToDoWithParameters()
        {
            BindingParameterCollection pl =
                new BindingParameterCollection();

            pl.Add(new ClientCredentials());
            BindingContext ctx =
                new BindingContext(new CustomBinding(), pl);

            Assert.IsNull(ctx.GetInnerProperty <ClientCredentials> ());

            CustomBinding binding = new CustomBinding(new HttpTransportBindingElement());

            ctx = new BindingContext(binding, pl);
            Assert.IsNull(ctx.GetInnerProperty <ClientCredentials> ());
        }
        internal IChannelListener <TChannel> BuildNegotiationChannelListener <TChannel>(BindingContext context) where TChannel : class, IChannel
        {
            SecurityCredentialsManager credentialsManager = base.IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>();

            if (credentialsManager == null)
            {
                credentialsManager = ServiceCredentials.CreateDefaultCredentials();
            }
            this.bootstrapSecurityBindingElement.ReaderQuotas = context.GetInnerProperty <XmlDictionaryReaderQuotas>();
            if (this.bootstrapSecurityBindingElement.ReaderQuotas == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("EncodingBindingElementDoesNotHandleReaderQuotas")));
            }
            TransportBindingElement element = context.RemainingBindingElements.Find <TransportBindingElement>();

            if (element != null)
            {
                this.bootstrapSecurityBindingElement.MaxReceivedMessageSize = element.MaxReceivedMessageSize;
            }
            SecurityProtocolFactory        factory  = this.bootstrapSecurityBindingElement.CreateSecurityProtocolFactory <TChannel>(base.IssuerBindingContext.Clone(), credentialsManager, true, base.IssuerBindingContext.Clone());
            MessageSecurityProtocolFactory factory2 = factory as MessageSecurityProtocolFactory;

            if (factory2 != null)
            {
                factory2.ApplyConfidentiality = factory2.ApplyIntegrity = factory2.RequireConfidentiality = factory2.RequireIntegrity = true;
                MessagePartSpecification parts = new MessagePartSpecification(true);
                factory2.ProtectionRequirements.OutgoingSignatureParts.AddParts(parts, this.RequestSecurityTokenResponseAction);
                factory2.ProtectionRequirements.OutgoingEncryptionParts.AddParts(parts, this.RequestSecurityTokenResponseAction);
                factory2.ProtectionRequirements.IncomingSignatureParts.AddParts(parts, this.RequestSecurityTokenAction);
                factory2.ProtectionRequirements.IncomingEncryptionParts.AddParts(parts, this.RequestSecurityTokenAction);
            }
            SecurityChannelListener <TChannel> listener = new SecurityChannelListener <TChannel>(this.bootstrapSecurityBindingElement, context)
            {
                SecurityProtocolFactory = factory,
                SendUnsecuredFaults     = !System.ServiceModel.Security.SecurityUtils.IsCompositeDuplexBinding(context)
            };
            ChannelBuilder channelBuilder = new ChannelBuilder(context, true);

            listener.InitializeListener(channelBuilder);
            this.shouldMatchRstWithEndpointFilter = System.ServiceModel.Security.SecurityUtils.ShouldMatchRstWithEndpointFilter(this.bootstrapSecurityBindingElement);
            return(listener);
        }
        void InitializeFactories()
        {
            ISecurityCapabilities      securityCapabilities = this.BootstrapSecurityBindingElement.GetProperty <ISecurityCapabilities>(this.IssuerBindingContext);
            SecurityCredentialsManager securityCredentials  = this.IssuerBindingContext.BindingParameters.Find <SecurityCredentialsManager>();

            if (securityCredentials == null)
            {
                securityCredentials = ClientCredentials.CreateDefaultCredentials();
            }
            BindingContext context = this.IssuerBindingContext;

            this.bootstrapSecurityBindingElement.ReaderQuotas = context.GetInnerProperty <XmlDictionaryReaderQuotas>();
            if (this.bootstrapSecurityBindingElement.ReaderQuotas == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.EncodingBindingElementDoesNotHandleReaderQuotas)));
            }
            TransportBindingElement transportBindingElement = context.RemainingBindingElements.Find <TransportBindingElement>();

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

            SecurityProtocolFactory securityProtocolFactory = this.BootstrapSecurityBindingElement.CreateSecurityProtocolFactory <IRequestChannel>(this.IssuerBindingContext.Clone(), securityCredentials, false, this.IssuerBindingContext.Clone());

            if (securityProtocolFactory is MessageSecurityProtocolFactory)
            {
                MessageSecurityProtocolFactory soapBindingFactory = securityProtocolFactory as MessageSecurityProtocolFactory;
                soapBindingFactory.ApplyConfidentiality             = soapBindingFactory.ApplyIntegrity
                                                                    = soapBindingFactory.RequireConfidentiality = soapBindingFactory.RequireIntegrity = true;

                soapBindingFactory.ProtectionRequirements.IncomingSignatureParts.ChannelParts.IsBodyIncluded = true;
                soapBindingFactory.ProtectionRequirements.OutgoingSignatureParts.ChannelParts.IsBodyIncluded = true;

                MessagePartSpecification bodyPart = new MessagePartSpecification(true);
                soapBindingFactory.ProtectionRequirements.IncomingSignatureParts.AddParts(bodyPart, IssueAction);
                soapBindingFactory.ProtectionRequirements.IncomingEncryptionParts.AddParts(bodyPart, IssueAction);
                soapBindingFactory.ProtectionRequirements.IncomingSignatureParts.AddParts(bodyPart, RenewAction);
                soapBindingFactory.ProtectionRequirements.IncomingEncryptionParts.AddParts(bodyPart, RenewAction);

                soapBindingFactory.ProtectionRequirements.OutgoingSignatureParts.AddParts(bodyPart, IssueResponseAction);
                soapBindingFactory.ProtectionRequirements.OutgoingEncryptionParts.AddParts(bodyPart, IssueResponseAction);
                soapBindingFactory.ProtectionRequirements.OutgoingSignatureParts.AddParts(bodyPart, RenewResponseAction);
                soapBindingFactory.ProtectionRequirements.OutgoingEncryptionParts.AddParts(bodyPart, RenewResponseAction);
            }
            securityProtocolFactory.PrivacyNoticeUri     = this.PrivacyNoticeUri;
            securityProtocolFactory.PrivacyNoticeVersion = this.privacyNoticeVersion;
            if (this.localAddress != null)
            {
                MessageFilter issueAndRenewFilter = new SessionActionFilter(this.standardsManager, this.IssueResponseAction.Value, this.RenewResponseAction.Value);
                context.BindingParameters.Add(new LocalAddressProvider(localAddress, issueAndRenewFilter));
            }
            ChannelBuilder channelBuilder = new ChannelBuilder(context, true);
            IChannelFactory <IRequestChannel> innerChannelFactory;

            // if the underlying transport does not support request/reply, wrap it inside
            // a service channel factory.
            if (channelBuilder.CanBuildChannelFactory <IRequestChannel>())
            {
                innerChannelFactory           = channelBuilder.BuildChannelFactory <IRequestChannel>();
                requiresManualReplyAddressing = true;
            }
            else
            {
                ClientRuntime clientRuntime = new ClientRuntime("RequestSecuritySession", NamingHelper.DefaultNamespace);
                clientRuntime.UseSynchronizationContext    = false;
                clientRuntime.AddTransactionFlowProperties = false;
                clientRuntime.ValidateMustUnderstand       = false;
                ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(channelBuilder, clientRuntime);

                ClientOperation issueOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "Issue", IssueAction.Value);
                issueOperation.Formatter = operationFormatter;
                serviceChannelFactory.ClientRuntime.Operations.Add(issueOperation);

                ClientOperation renewOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "Renew", RenewAction.Value);
                renewOperation.Formatter = operationFormatter;
                serviceChannelFactory.ClientRuntime.Operations.Add(renewOperation);
                innerChannelFactory           = new RequestChannelFactory(serviceChannelFactory);
                requiresManualReplyAddressing = false;
            }

            SecurityChannelFactory <IRequestChannel> securityChannelFactory = new SecurityChannelFactory <IRequestChannel>(
                securityCapabilities, this.IssuerBindingContext, channelBuilder, securityProtocolFactory, innerChannelFactory);

            // attach the ExtendedProtectionPolicy to the securityProtcolFactory so it will be
            // available when building the channel.
            if (transportBindingElement != null)
            {
                if (securityChannelFactory.SecurityProtocolFactory != null)
                {
                    securityChannelFactory.SecurityProtocolFactory.ExtendedProtectionPolicy = transportBindingElement.GetProperty <ExtendedProtectionPolicy>(context);
                }
            }

            this.rstChannelFactory = securityChannelFactory;
            this.messageVersion    = securityChannelFactory.MessageVersion;
        }
Пример #29
0
 // Call the inner property.
 public override T GetProperty <T>(BindingContext context)
 {
     return(context.GetInnerProperty <T>());
 }
        /// <summary>
        /// Returns a typed object requested, if present, from the appropriate layer in the binding element stack.
        /// </summary>
        public override T GetProperty <T>(BindingContext context)
        {
            T result = _innerBindingElement.GetProperty <T>(context) ?? context.GetInnerProperty <T>();

            return(result);
        }
        /// <summary>
        /// Increases the quotas in the specified binding.
        /// </summary>        
        public static Binding IncreaseBindingQuotas(Binding binding)
        {
            CustomBinding newBinding = new CustomBinding(binding);
            newBinding.ReceiveTimeout = TimeSpan.MaxValue;
            newBinding.SendTimeout = TimeSpan.MaxValue;

            BindingContext bcontext = new BindingContext(newBinding, new BindingParameterCollection());
            XmlDictionaryReaderQuotas xmlDictReaderQuotas = bcontext.GetInnerProperty<XmlDictionaryReaderQuotas>();

            if (xmlDictReaderQuotas != null)
            {
                xmlDictReaderQuotas.MaxArrayLength = int.MaxValue;
                xmlDictReaderQuotas.MaxBytesPerRead = int.MaxValue;
                xmlDictReaderQuotas.MaxDepth = int.MaxValue;
                xmlDictReaderQuotas.MaxNameTableCharCount = int.MaxValue;
                xmlDictReaderQuotas.MaxStringContentLength = int.MaxValue;
            }

            TransportBindingElement transport = bcontext.RemainingBindingElements.Find<TransportBindingElement>();

            if (transport != null)
            {
                if (typeof (HttpTransportBindingElement) == transport.GetType()) // http
                {
                    HttpTransportBindingElement httpTransport = transport as HttpTransportBindingElement;

                    // Are we on a streaming transport? Then we can make MaxReceivedMessageSize to 
                    // long.MaxValue. Otherwise we have to set it to int.MaxValue as that's the max buffer size.
                    if (httpTransport.TransferMode == TransferMode.Streamed ||
                        httpTransport.TransferMode == TransferMode.StreamedRequest)
                    {
                        httpTransport.MaxReceivedMessageSize = long.MaxValue;
                    }
                    else
                    {
                        httpTransport.MaxReceivedMessageSize = int.MaxValue;
                    }
                    httpTransport.MaxBufferSize = int.MaxValue;
                }
                else if (typeof (TcpTransportBindingElement) == transport.GetType()) // tcp                            
                {
                    TcpTransportBindingElement tcpTransport = transport as TcpTransportBindingElement;

                    if (tcpTransport.TransferMode == TransferMode.Streamed ||
                        tcpTransport.TransferMode == TransferMode.StreamedRequest)
                    {
                        tcpTransport.MaxReceivedMessageSize = long.MaxValue;
                    }
                    else
                    {
                        tcpTransport.MaxReceivedMessageSize = int.MaxValue;
                    }
                    tcpTransport.MaxBufferSize = int.MaxValue;
                }
                else if (typeof (NamedPipeTransportBindingElement) == transport.GetType()) // pipe
                {
                    NamedPipeTransportBindingElement pipeTransport = transport as NamedPipeTransportBindingElement;

                    if (pipeTransport.TransferMode == TransferMode.Streamed ||
                        pipeTransport.TransferMode == TransferMode.StreamedRequest)
                    {
                        pipeTransport.MaxReceivedMessageSize = long.MaxValue;
                    }
                    else
                    {
                        pipeTransport.MaxReceivedMessageSize = int.MaxValue;
                    }
                    pipeTransport.MaxBufferSize = int.MaxValue;
                }
                else if (typeof (MsmqTransportBindingElement) == transport.GetType()) // msmq
                {
                    MsmqTransportBindingElement msmqTrasport = transport as MsmqTransportBindingElement;
                    msmqTrasport.MaxReceivedMessageSize = long.MaxValue;
                }
                else
                {
                    // We don't know the transport type (probably a custom transport). So let's max it out to the int.MaxValue.
                    transport.MaxReceivedMessageSize = int.MaxValue;
                }
            }

            return newBinding;
        }
		public void GetInnerPropertyIsNothingToDoWithParameters ()
		{
			BindingParameterCollection pl =
				new BindingParameterCollection ();
			pl.Add (new ClientCredentials ());
			BindingContext ctx =
				new BindingContext (new CustomBinding (), pl);
			Assert.IsNull (ctx.GetInnerProperty<ClientCredentials> ());

			CustomBinding binding = new CustomBinding (new HttpTransportBindingElement ());
			ctx = new BindingContext (binding, pl);
			Assert.IsNull (ctx.GetInnerProperty<ClientCredentials> ());
		}
        /// <summary>
        /// Verifies that the throttling settings in a given binding are maxed out.
        /// </summary>
        private void VerifyBindingSettings(Binding binding)
        {
            CustomBinding customBinding = new CustomBinding(binding);
            BindingContext bctx = new BindingContext(customBinding, new BindingParameterCollection());

            // Verify binding timeouts.
            VerifyBindingTimeouts(binding);

            // Verify the XmlDictionaryReaderQuotas.
            XmlDictionaryReaderQuotas dictQuotas = bctx.GetInnerProperty<XmlDictionaryReaderQuotas>();
            VerifyXmlDictionaryReaderQuotas(dictQuotas, binding.Name);

            // Verify the transport.
            TransportBindingElement transport = bctx.RemainingBindingElements.Find<TransportBindingElement>();
            VerifyTransportQuotas(transport, binding.Name);
        }