public static IConnection UpgradeConnection(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts)
        {
            ConnectionStream connectionStream = new ConnectionStream(connection, defaultTimeouts);
            Stream           stream           = upgradeAcceptor.AcceptUpgrade(connectionStream);

            if (upgradeAcceptor is StreamSecurityUpgradeAcceptor)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceUtility.TraceEvent(TraceEventType.Information,
                                            TraceCode.StreamSecurityUpgradeAccepted, SR.GetString(SR.TraceCodeStreamSecurityUpgradeAccepted),
                                            new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null);
                }
            }

            return(new StreamConnection(stream, connectionStream));
        }
            void CompleteAcceptUpgrade(IAsyncResult result)
            {
                Stream stream;
                bool   endSucceeded = false;

                try
                {
                    stream       = this.upgradeAcceptor.EndAcceptUpgrade(result);
                    endSucceeded = true;
                }
                finally
                {
                    if (upgradeAcceptor is StreamSecurityUpgradeAcceptor)
                    {
                        if (DiagnosticUtility.ShouldTraceInformation && endSucceeded)
                        {
                            TraceUtility.TraceEvent(TraceEventType.Information,
                                                    TraceCode.StreamSecurityUpgradeAccepted, SR.GetString(SR.TraceCodeStreamSecurityUpgradeAccepted),
                                                    new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), this, null);
                        }
                    }
                }
                this.connection = new StreamConnection(stream, this.connectionStream);
            }
        public static IConnection UpgradeConnection(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts)
        {
            ConnectionStream connectionStream = new ConnectionStream(connection, defaultTimeouts);
            Stream stream = upgradeAcceptor.AcceptUpgrade(connectionStream);
            if (upgradeAcceptor is StreamSecurityUpgradeAcceptor)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceUtility.TraceEvent(TraceEventType.Information,
                        TraceCode.StreamSecurityUpgradeAccepted, SR.GetString(SR.TraceCodeStreamSecurityUpgradeAccepted),
                        new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null);
                }
            }

            return new StreamConnection(stream, connectionStream);
        }
        public static IConnection UpgradeConnection(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts)
        {
            ConnectionStream stream  = new ConnectionStream(connection, defaultTimeouts);
            Stream           stream2 = upgradeAcceptor.AcceptUpgrade(stream);

            if ((upgradeAcceptor is StreamSecurityUpgradeAcceptor) && DiagnosticUtility.ShouldTraceInformation)
            {
                TraceUtility.TraceEvent(TraceEventType.Information, 0x4002e, System.ServiceModel.SR.GetString("TraceCodeStreamSecurityUpgradeAccepted"), new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null);
            }
            return(new StreamConnection(stream2, stream));
        }
Esempio n. 5
0
        ChannelBinding IStreamUpgradeChannelBindingProvider.GetChannelBinding(StreamUpgradeAcceptor upgradeAcceptor, ChannelBindingKind kind)
        {
            if (upgradeAcceptor == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("upgradeAcceptor");
            }
            SslStreamSecurityUpgradeAcceptor acceptor = upgradeAcceptor as SslStreamSecurityUpgradeAcceptor;

            if (acceptor == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("upgradeAcceptor", System.ServiceModel.SR.GetString("UnsupportedUpgradeAcceptor", new object[] { upgradeAcceptor.GetType() }));
            }
            if (kind != ChannelBindingKind.Endpoint)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("kind", System.ServiceModel.SR.GetString("StreamUpgradeUnsupportedChannelBindingKind", new object[] { base.GetType(), kind }));
            }
            return(acceptor.ChannelBinding);
        }
        ChannelBinding IStreamUpgradeChannelBindingProvider.GetChannelBinding(StreamUpgradeAcceptor upgradeAcceptor, ChannelBindingKind kind)
        {
            if (upgradeAcceptor == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("upgradeAcceptor");
            }

            SslStreamSecurityUpgradeAcceptor sslupgradeAcceptor = upgradeAcceptor as SslStreamSecurityUpgradeAcceptor;

            if (sslupgradeAcceptor == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("upgradeAcceptor", string.Format(SRServiceModel.UnsupportedUpgradeAcceptor, upgradeAcceptor.GetType()));
            }

            if (kind != ChannelBindingKind.Endpoint)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("kind", string.Format(SRServiceModel.StreamUpgradeUnsupportedChannelBindingKind, this.GetType(), kind));
            }

            return(sslupgradeAcceptor.ChannelBinding);
        }