Exemplo n.º 1
0
            internal static Message End(IAsyncResult result)
            {
                SecurityChannelFactory <TChannel> .RequestChannelSendAsyncResult self = result as SecurityChannelFactory <TChannel> .RequestChannelSendAsyncResult;
                ApplySecurityAndSendAsyncResult <IRequestChannel> .OnEnd(self);

                return(self.reply);
            }
Exemplo n.º 2
0
                public OpenAsyncResult(SecurityChannelFactory <TChannel> .ClientSecurityChannel <UChannel> clientChannel, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
                {
                    this.timeoutHelper = new TimeoutHelper(timeout);
                    this.clientChannel = clientChannel;
                    SecurityProtocol securityProtocol = this.clientChannel.SecurityProtocolFactory.CreateSecurityProtocol(this.clientChannel.to, this.clientChannel.Via, null, typeof(TChannel) == typeof(IRequestChannel), this.timeoutHelper.RemainingTime());

                    if (this.OnCreateSecurityProtocolComplete(securityProtocol))
                    {
                        base.Complete(true);
                    }
                }
Exemplo n.º 3
0
        protected override TChannel OnCreateChannel(EndpointAddress address, Uri via)
        {
            this.ThrowIfDisposed();
            if (this.SessionMode)
            {
                return(this.sessionClientSettings.OnCreateChannel(address, via));
            }
            if (typeof(TChannel) == typeof(IOutputChannel))
            {
                var ret = new SecurityChannelFactory <TChannel> .SecurityOutputChannel((ChannelManagerBase)this, this.securityProtocolFactory, ((IChannelFactory <IOutputChannel>) this.InnerChannelFactory).CreateChannel(address, via), address, via);

                return((TChannel)Convert.ChangeType(ret, typeof(TChannel)));
            }
            if (typeof(TChannel) == typeof(IOutputSessionChannel))
            {
                var ret = new SecurityChannelFactory <TChannel> .SecurityOutputSessionChannel((ChannelManagerBase)this, this.securityProtocolFactory, ((IChannelFactory <IOutputSessionChannel>) this.InnerChannelFactory).CreateChannel(address, via), address, via);

                return((TChannel)Convert.ChangeType(ret, typeof(TChannel)));
            }
            if (typeof(TChannel) == typeof(IDuplexChannel))
            {
                var ret = new SecurityChannelFactory <TChannel> .SecurityDuplexChannel((ChannelManagerBase)this, this.securityProtocolFactory, ((IChannelFactory <IDuplexChannel>) this.InnerChannelFactory).CreateChannel(address, via), address, via);

                return((TChannel)Convert.ChangeType(ret, typeof(TChannel)));
            }
            if (typeof(TChannel) == typeof(IDuplexSessionChannel))
            {
                var ret = new SecurityChannelFactory <TChannel> .SecurityDuplexSessionChannel((ChannelManagerBase)this, this.securityProtocolFactory, ((IChannelFactory <IDuplexSessionChannel>) this.InnerChannelFactory).CreateChannel(address, via), address, via);

                return((TChannel)Convert.ChangeType(ret, typeof(TChannel)));
            }
            if (typeof(TChannel) == typeof(IRequestChannel))
            {
                var ret = new SecurityChannelFactory <TChannel> .SecurityRequestChannel((ChannelManagerBase)this, this.securityProtocolFactory, ((IChannelFactory <IRequestChannel>) this.InnerChannelFactory).CreateChannel(address, via), address, via);

                return((TChannel)Convert.ChangeType(ret, typeof(TChannel)));
            }
            var retFinal = new SecurityChannelFactory <TChannel> .SecurityRequestSessionChannel((ChannelManagerBase)this, this.securityProtocolFactory, ((IChannelFactory <IRequestSessionChannel>) this.InnerChannelFactory).CreateChannel(address, via), address, via);

            return((TChannel)Convert.ChangeType(retFinal, typeof(TChannel)));
        }
Exemplo n.º 4
0
            public virtual IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state)
            {
                if (base.DoneReceivingInCurrentState())
                {
                    return(new DoneReceivingAsyncResult(callback, state));
                }
                SecurityChannelFactory <TChannel> .ClientDuplexReceiveMessageAndVerifySecurityAsyncResult result = new SecurityChannelFactory <TChannel> .ClientDuplexReceiveMessageAndVerifySecurityAsyncResult((SecurityChannelFactory <TChannel> .SecurityDuplexChannel) this, this.InnerDuplexChannel, timeout, callback, state);

                result.Start();
                return(result);
            }
Exemplo n.º 5
0
 public RequestChannelSendAsyncResult(Message message, SecurityProtocol protocol, IRequestChannel channel, SecurityChannelFactory <TChannel> .SecurityRequestChannel securityChannel, TimeSpan timeout, AsyncCallback callback, object state) : base(protocol, channel, timeout, callback, state)
 {
     this.securityChannel = securityChannel;
     base.Begin(message, null);
 }
Exemplo n.º 6
0
 private static void OpenSecurityProtocolCallback(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         SecurityChannelFactory <TChannel> .ClientSecurityChannel <UChannel> .OpenAsyncResult asyncState = result.AsyncState as SecurityChannelFactory <TChannel> .ClientSecurityChannel <UChannel> .OpenAsyncResult;
         if (asyncState == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("InvalidAsyncResult"), "result"));
         }
         Exception exception = null;
         bool      flag      = false;
         try
         {
             asyncState.clientChannel.SecurityProtocol.EndOpen(result);
             flag = asyncState.OnSecurityProtocolOpenComplete();
         }
         catch (Exception exception2)
         {
             if (Fx.IsFatal(exception2))
             {
                 throw;
             }
             exception = exception2;
             flag      = true;
         }
         if (flag)
         {
             asyncState.Complete(false, exception);
         }
     }
 }
Exemplo n.º 7
0
 public ClientDuplexReceiveMessageAndVerifySecurityAsyncResult(SecurityChannelFactory <TChannel> .SecurityDuplexChannel channel, IDuplexChannel innerChannel, TimeSpan timeout, AsyncCallback callback, object state) : base(innerChannel, timeout, callback, state)
 {
     this.channel = channel;
 }
Exemplo n.º 8
0
 public SecurityOutputSessionChannel(IOutputSessionChannel innerChannel, SecurityChannelFactory <IOutputSessionChannel> source)
     : base(innerChannel)
 {
     this.source = source;
     InitializeSecurityFunctionality(source.SecuritySupport);
 }
Exemplo n.º 9
0
 public SecurityRequestChannel(IRequestChannel innerChannel, SecurityChannelFactory <IRequestChannel> source)
     : base(innerChannel)
 {
     this.source = source;
     InitializeSecurityFunctionality(source.SecuritySupport);
 }
        protected override IChannelFactory <TChannel> BuildChannelFactoryCore <TChannel>(BindingContext context)
        {
            ISecurityCapabilities      securityCapabilities = this.GetProperty <ISecurityCapabilities>(context);
            SecurityCredentialsManager credentialsManager   = context.BindingParameters.Find <SecurityCredentialsManager>();

            if (credentialsManager == null)
            {
                credentialsManager = ClientCredentials.CreateDefaultCredentials();
            }

            SecureConversationSecurityTokenParameters scParameters = null;

            if (this.EndpointSupportingTokenParameters.Endorsing.Count > 0)
            {
                scParameters = this.EndpointSupportingTokenParameters.Endorsing[0] as SecureConversationSecurityTokenParameters;
            }

            // This adds the demuxer element to the context

            bool           requireDemuxer = RequiresChannelDemuxer();
            ChannelBuilder channelBuilder = new ChannelBuilder(context, requireDemuxer);

            if (requireDemuxer)
            {
                ApplyPropertiesOnDemuxer(channelBuilder, context);
            }
            BindingContext issuerBindingContext = context.Clone();

            SecurityChannelFactory <TChannel> channelFactory;

            if (scParameters != null)
            {
                if (scParameters.BootstrapSecurityBindingElement == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SecureConversationSecurityTokenParametersRequireBootstrapBinding)));
                }

                scParameters.IssuerBindingContext = issuerBindingContext;
                if (scParameters.RequireCancellation)
                {
                    SessionSymmetricTransportSecurityProtocolFactory sessionFactory = new SessionSymmetricTransportSecurityProtocolFactory();
                    sessionFactory.SecurityTokenParameters = scParameters.Clone();
                    ((SecureConversationSecurityTokenParameters)sessionFactory.SecurityTokenParameters).IssuerBindingContext = issuerBindingContext;
                    this.EndpointSupportingTokenParameters.Endorsing.RemoveAt(0);
                    try
                    {
                        base.ConfigureProtocolFactory(sessionFactory, credentialsManager, false, issuerBindingContext, context.Binding);
                    }
                    finally
                    {
                        this.EndpointSupportingTokenParameters.Endorsing.Insert(0, scParameters);
                    }

                    SecuritySessionClientSettings <TChannel> sessionClientSettings = new SecuritySessionClientSettings <TChannel>();
                    sessionClientSettings.ChannelBuilder                = channelBuilder;
                    sessionClientSettings.KeyRenewalInterval            = this.LocalClientSettings.SessionKeyRenewalInterval;
                    sessionClientSettings.KeyRolloverInterval           = this.LocalClientSettings.SessionKeyRolloverInterval;
                    sessionClientSettings.TolerateTransportFailures     = this.LocalClientSettings.ReconnectTransportOnFailure;
                    sessionClientSettings.CanRenewSession               = scParameters.CanRenewSession;
                    sessionClientSettings.IssuedSecurityTokenParameters = scParameters.Clone();
                    ((SecureConversationSecurityTokenParameters)sessionClientSettings.IssuedSecurityTokenParameters).IssuerBindingContext = issuerBindingContext;
                    sessionClientSettings.SecurityStandardsManager = sessionFactory.StandardsManager;
                    sessionClientSettings.SessionProtocolFactory   = sessionFactory;
                    channelFactory = new SecurityChannelFactory <TChannel>(securityCapabilities, context, sessionClientSettings);
                }
                else
                {
                    TransportSecurityProtocolFactory protocolFactory = new TransportSecurityProtocolFactory();
                    this.EndpointSupportingTokenParameters.Endorsing.RemoveAt(0);
                    try
                    {
                        base.ConfigureProtocolFactory(protocolFactory, credentialsManager, false, issuerBindingContext, context.Binding);
                        SecureConversationSecurityTokenParameters acceleratedTokenParameters = (SecureConversationSecurityTokenParameters)scParameters.Clone();
                        acceleratedTokenParameters.IssuerBindingContext = issuerBindingContext;
                        protocolFactory.SecurityBindingElement.EndpointSupportingTokenParameters.Endorsing.Insert(0, acceleratedTokenParameters);
                    }
                    finally
                    {
                        this.EndpointSupportingTokenParameters.Endorsing.Insert(0, scParameters);
                    }

                    channelFactory = new SecurityChannelFactory <TChannel>(securityCapabilities, context, channelBuilder, protocolFactory);
                }
            }
            else
            {
                SecurityProtocolFactory protocolFactory = this.CreateSecurityProtocolFactory <TChannel>(
                    context, credentialsManager, false, issuerBindingContext);
                channelFactory = new SecurityChannelFactory <TChannel>(securityCapabilities, context, channelBuilder, protocolFactory);
            }

            return(channelFactory);
        }
        protected override IChannelFactory <TChannel> BuildChannelFactoryCore <TChannel>(BindingContext context)
        {
            ISecurityCapabilities      securityCapabilities = this.GetProperty <ISecurityCapabilities>(context);
            SecurityCredentialsManager credentialsManager   = context.BindingParameters.Find <SecurityCredentialsManager>();

            if (credentialsManager == null)
            {
                credentialsManager = ClientCredentials.CreateDefaultCredentials();
            }

            // This adds the demuxer element to the context. We add a demuxer element only if the binding is configured to do
            // secure conversation or negotiation
            bool           requireDemuxer = RequiresChannelDemuxer();
            ChannelBuilder channelBuilder = new ChannelBuilder(context, requireDemuxer);

            if (requireDemuxer)
            {
                ApplyPropertiesOnDemuxer(channelBuilder, context);
            }
            BindingContext issuerBindingContext = context.Clone();

            SecurityChannelFactory <TChannel> channelFactory;

            if (this.ProtectionTokenParameters is SecureConversationSecurityTokenParameters)
            {
                SecureConversationSecurityTokenParameters scParameters = (SecureConversationSecurityTokenParameters)this.ProtectionTokenParameters;
                if (scParameters.BootstrapSecurityBindingElement == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SecureConversationSecurityTokenParametersRequireBootstrapBinding)));
                }

                BindingContext scIssuerBindingContext = issuerBindingContext.Clone();
                scIssuerBindingContext.BindingParameters.Remove <ChannelProtectionRequirements>();
                scIssuerBindingContext.BindingParameters.Add(scParameters.BootstrapProtectionRequirements);

                if (scParameters.RequireCancellation)
                {
                    SessionSymmetricMessageSecurityProtocolFactory sessionFactory = new SessionSymmetricMessageSecurityProtocolFactory();
                    sessionFactory.SecurityTokenParameters = scParameters.Clone();
                    ((SecureConversationSecurityTokenParameters)sessionFactory.SecurityTokenParameters).IssuerBindingContext = scIssuerBindingContext;
                    sessionFactory.ApplyConfidentiality           = true;
                    sessionFactory.RequireConfidentiality         = true;
                    sessionFactory.ApplyIntegrity                 = true;
                    sessionFactory.RequireIntegrity               = true;
                    sessionFactory.IdentityVerifier               = this.LocalClientSettings.IdentityVerifier;
                    sessionFactory.DoRequestSignatureConfirmation = this.RequireSignatureConfirmation;
                    sessionFactory.MessageProtectionOrder         = this.MessageProtectionOrder;
                    sessionFactory.IdentityVerifier               = this.LocalClientSettings.IdentityVerifier;
                    sessionFactory.ProtectionRequirements.Add(SecurityBindingElement.ComputeProtectionRequirements(this, context.BindingParameters, context.Binding.Elements, false));
                    base.ConfigureProtocolFactory(sessionFactory, credentialsManager, false, issuerBindingContext, context.Binding);

                    SecuritySessionClientSettings <TChannel> sessionClientSettings = new SecuritySessionClientSettings <TChannel>();
                    sessionClientSettings.ChannelBuilder                = channelBuilder;
                    sessionClientSettings.KeyRenewalInterval            = this.LocalClientSettings.SessionKeyRenewalInterval;
                    sessionClientSettings.CanRenewSession               = scParameters.CanRenewSession;
                    sessionClientSettings.KeyRolloverInterval           = this.LocalClientSettings.SessionKeyRolloverInterval;
                    sessionClientSettings.TolerateTransportFailures     = this.LocalClientSettings.ReconnectTransportOnFailure;
                    sessionClientSettings.IssuedSecurityTokenParameters = scParameters.Clone();
                    ((SecureConversationSecurityTokenParameters)sessionClientSettings.IssuedSecurityTokenParameters).IssuerBindingContext = issuerBindingContext;
                    sessionClientSettings.SecurityStandardsManager = sessionFactory.StandardsManager;
                    sessionClientSettings.SessionProtocolFactory   = sessionFactory;
                    channelFactory = new SecurityChannelFactory <TChannel>(securityCapabilities, context, sessionClientSettings);
                }
                else
                {
                    SymmetricSecurityProtocolFactory protocolFactory = new SymmetricSecurityProtocolFactory();

                    protocolFactory.SecurityTokenParameters = scParameters.Clone();
                    ((SecureConversationSecurityTokenParameters)protocolFactory.SecurityTokenParameters).IssuerBindingContext = scIssuerBindingContext;
                    protocolFactory.ApplyConfidentiality           = true;
                    protocolFactory.RequireConfidentiality         = true;
                    protocolFactory.ApplyIntegrity                 = true;
                    protocolFactory.RequireIntegrity               = true;
                    protocolFactory.IdentityVerifier               = this.LocalClientSettings.IdentityVerifier;
                    protocolFactory.DoRequestSignatureConfirmation = this.RequireSignatureConfirmation;
                    protocolFactory.MessageProtectionOrder         = this.MessageProtectionOrder;
                    protocolFactory.ProtectionRequirements.Add(SecurityBindingElement.ComputeProtectionRequirements(this, context.BindingParameters, context.Binding.Elements, false));
                    base.ConfigureProtocolFactory(protocolFactory, credentialsManager, false, issuerBindingContext, context.Binding);

                    channelFactory = new SecurityChannelFactory <TChannel>(securityCapabilities, context, channelBuilder, protocolFactory);
                }
            }
            else
            {
                SecurityProtocolFactory protocolFactory = this.CreateSecurityProtocolFactory <TChannel>(context, credentialsManager, false, issuerBindingContext);
                channelFactory = new SecurityChannelFactory <TChannel>(securityCapabilities, context, channelBuilder, protocolFactory);
            }

            return(channelFactory);
        }
Exemplo n.º 12
0
                private static void OpenInnerChannelCallback(IAsyncResult result)
                {
                    if (result == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError((Exception) new ArgumentNullException("result"));
                    }
                    if (result.CompletedSynchronously)
                    {
                        return;
                    }
                    SecurityChannelFactory <TChannel> .ClientSecurityChannel <UChannel> .OpenAsyncResult asyncState = result.AsyncState as SecurityChannelFactory <TChannel> .ClientSecurityChannel <UChannel> .OpenAsyncResult;
                    if (asyncState == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError((Exception) new ArgumentException(SR.GetString("InvalidAsyncResult"), "result"));
                    }
                    Exception exception = (Exception)null;

                    try
                    {
                        asyncState.clientChannel.InnerChannel.EndOpen(result);
                    }
                    catch (Exception ex)
                    {
                        if (Fx.IsFatal(ex))
                        {
                            throw;
                        }
                        else
                        {
                            exception = ex;
                        }
                    }
                    asyncState.Complete(false, exception);
                }
Exemplo n.º 13
0
                private static void OpenSecurityProtocolCallback(IAsyncResult result)
                {
                    if (result.CompletedSynchronously)
                    {
                        return;
                    }
                    SecurityChannelFactory <TChannel> .ClientSecurityChannel <UChannel> .OpenAsyncResult asyncState = result.AsyncState as SecurityChannelFactory <TChannel> .ClientSecurityChannel <UChannel> .OpenAsyncResult;
                    if (asyncState == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError((Exception) new ArgumentException(SR.GetString("InvalidAsyncResult"), "result"));
                    }
#if FEATURE_CORECLR
                    throw new NotImplementedException("SecurityProtocol.EndOpen is not supported in .NET Core");
#else
                    Exception exception = (Exception)null;
                    bool      flag;
                    try
                    {
                        asyncState.clientChannel.SecurityProtocol.EndOpen(result);
                        flag = asyncState.OnSecurityProtocolOpenComplete();
                    }
                    catch (Exception ex)
                    {
                        if (Fx.IsFatal(ex))
                        {
                            throw;
                        }
                        else
                        {
                            exception = ex;
                            flag      = true;
                        }
                    }
                    if (!flag)
                    {
                        return;
                    }
                    asyncState.Complete(false, exception);
#endif
                }
Exemplo n.º 14
0
        /*internal override bool RequiresChannelDemuxer()
         * {
         * if (!base.RequiresChannelDemuxer())
         *  return this.RequiresChannelDemuxer(this.ProtectionTokenParameters);
         * return true;
         * }*/

        protected override IChannelFactory <TChannel> BuildChannelFactoryCore <TChannel>(BindingContext context)
        {
            ISecurityCapabilities      property           = this.GetProperty <ISecurityCapabilities>(context);
            SecurityCredentialsManager credentialsManager = context.BindingParameters.Find <SecurityCredentialsManager>() ?? (SecurityCredentialsManager)ClientCredentials.CreateDefaultCredentials();
            bool           addChannelDemuxerIfRequired    = this.RequiresChannelDemuxer();
            ChannelBuilder channelBuilder = new ChannelBuilder(context, addChannelDemuxerIfRequired);

            if (addChannelDemuxerIfRequired)
            {
#if FEATURE_CORECLR
                throw new NotImplementedException("ApplyPropertiesOnDemuxer is not supported in .NET Core");
#else
                this.ApplyPropertiesOnDemuxer(channelBuilder, context);
#endif
            }
            BindingContext bindingContext1 = context.Clone();
            SecurityChannelFactory <TChannel> securityChannelFactory;
            if (this.ProtectionTokenParameters is SecureConversationSecurityTokenParameters)
            {
                SecureConversationSecurityTokenParameters protectionTokenParameters = (SecureConversationSecurityTokenParameters)this.ProtectionTokenParameters;
                if (protectionTokenParameters.BootstrapSecurityBindingElement == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError((Exception) new InvalidOperationException(SR.GetString("SecureConversationSecurityTokenParametersRequireBootstrapBinding")));
                }
                BindingContext bindingContext2 = bindingContext1.Clone();
                bindingContext2.BindingParameters.Remove <ChannelProtectionRequirements>();
// BootstrapProtectionRequirements not supported
//         bindingContext2.BindingParameters.Add((object) protectionTokenParameters.BootstrapProtectionRequirements);
                if (protectionTokenParameters.RequireCancellation)
                {
                    SessionSymmetricMessageSecurityProtocolFactory securityProtocolFactory = new SessionSymmetricMessageSecurityProtocolFactory();
                    securityProtocolFactory.SecurityTokenParameters = protectionTokenParameters.Clone();
                    ((SecureConversationSecurityTokenParameters)securityProtocolFactory.SecurityTokenParameters).IssuerBindingContext = bindingContext2;
                    securityProtocolFactory.ApplyConfidentiality           = true;
                    securityProtocolFactory.RequireConfidentiality         = true;
                    securityProtocolFactory.ApplyIntegrity                 = true;
                    securityProtocolFactory.RequireIntegrity               = true;
                    securityProtocolFactory.IdentityVerifier               = this.LocalClientSettings.IdentityVerifier;
                    securityProtocolFactory.DoRequestSignatureConfirmation = this.RequireSignatureConfirmation;
                    securityProtocolFactory.MessageProtectionOrder         = this.MessageProtectionOrder;
                    securityProtocolFactory.IdentityVerifier               = this.LocalClientSettings.IdentityVerifier;
                    securityProtocolFactory.ProtectionRequirements.Add(SecurityBindingElement.ComputeProtectionRequirements((SecurityBindingElement)this, context.BindingParameters, context.Binding.Elements, false));
                    this.ConfigureProtocolFactory((SecurityProtocolFactory)securityProtocolFactory, credentialsManager, false, bindingContext1, (Binding)context.Binding);
                    SecuritySessionClientSettings <TChannel> sessionClientSettings = new SecuritySessionClientSettings <TChannel>();
                    sessionClientSettings.ChannelBuilder                = channelBuilder;
                    sessionClientSettings.KeyRenewalInterval            = this.LocalClientSettings.SessionKeyRenewalInterval;
                    sessionClientSettings.CanRenewSession               = protectionTokenParameters.CanRenewSession;
                    sessionClientSettings.KeyRolloverInterval           = this.LocalClientSettings.SessionKeyRolloverInterval;
                    sessionClientSettings.TolerateTransportFailures     = this.LocalClientSettings.ReconnectTransportOnFailure;
                    sessionClientSettings.IssuedSecurityTokenParameters = protectionTokenParameters.Clone();
                    ((SecureConversationSecurityTokenParameters)sessionClientSettings.IssuedSecurityTokenParameters).IssuerBindingContext = bindingContext1;
                    sessionClientSettings.SecurityStandardsManager = securityProtocolFactory.StandardsManager;
                    Console.WriteLine("Assigned sessionClientSettings.SessionProtocolFactory");
                    sessionClientSettings.SessionProtocolFactory = (SecurityProtocolFactory)securityProtocolFactory;
                    securityChannelFactory = new SecurityChannelFactory <TChannel>(property, context, sessionClientSettings);
                }
                else
                {
#if FEATURE_CORECLR
                    throw new NotImplementedException("SymmetricSecurityProtocolFactory not supported in .NET Core");
#else
                    SymmetricSecurityProtocolFactory securityProtocolFactory = new SymmetricSecurityProtocolFactory();
                    securityProtocolFactory.SecurityTokenParameters = protectionTokenParameters.Clone();
                    ((SecureConversationSecurityTokenParameters)securityProtocolFactory.SecurityTokenParameters).IssuerBindingContext = bindingContext2;
                    securityProtocolFactory.ApplyConfidentiality           = true;
                    securityProtocolFactory.RequireConfidentiality         = true;
                    securityProtocolFactory.ApplyIntegrity                 = true;
                    securityProtocolFactory.RequireIntegrity               = true;
                    securityProtocolFactory.IdentityVerifier               = this.LocalClientSettings.IdentityVerifier;
                    securityProtocolFactory.DoRequestSignatureConfirmation = this.RequireSignatureConfirmation;
                    securityProtocolFactory.MessageProtectionOrder         = this.MessageProtectionOrder;
                    securityProtocolFactory.ProtectionRequirements.Add(SecurityBindingElement.ComputeProtectionRequirements((SecurityBindingElement)this, context.BindingParameters, context.Binding.Elements, false));
                    this.ConfigureProtocolFactory((SecurityProtocolFactory)securityProtocolFactory, credentialsManager, false, bindingContext1, (Binding)context.Binding);
                    securityChannelFactory = new SecurityChannelFactory <TChannel>(property, context, channelBuilder, (SecurityProtocolFactory)securityProtocolFactory);
#endif
                }
            }
            else
            {
                SecurityProtocolFactory securityProtocolFactory = this.CreateSecurityProtocolFactory <TChannel>(context, credentialsManager, false, bindingContext1);
                securityChannelFactory = new SecurityChannelFactory <TChannel>(property, context, channelBuilder, securityProtocolFactory);
            }
            return((IChannelFactory <TChannel>)securityChannelFactory);
        }