internal WSHttpRelaySecurity(EndToEndSecurityMode mode, Microsoft.ServiceBus.RelayClientAuthenticationType relayClientAuthenticationType, HttpRelayTransportSecurity transportSecurity, NonDualMessageSecurityOverRelayHttp messageSecurity)
 {
     this.mode = mode;
     this.relayClientAuthenticationType = relayClientAuthenticationType;
     this.transportSecurity             = (transportSecurity == null ? WSHttpRelaySecurity.GetDefaultHttpTransportSecurity() : transportSecurity);
     this.messageSecurity = (messageSecurity == null ? new NonDualMessageSecurityOverRelayHttp() : messageSecurity);
 }
        internal static bool TryCreate(SecurityBindingElement sbe, Microsoft.ServiceBus.UnifiedSecurityMode mode, HttpRelayTransportSecurity transportSecurity, Microsoft.ServiceBus.RelayClientAuthenticationType relayClientAuthenticationType, bool isReliableSessionEnabled, out WSHttpRelaySecurity security)
        {
            security = null;
            NonDualMessageSecurityOverRelayHttp nonDualMessageSecurityOverRelayHttp = null;
            EndToEndSecurityMode relaySecurityMode = EndToEndSecurityMode.None;

            if (sbe == null)
            {
                mode = mode & (Microsoft.ServiceBus.UnifiedSecurityMode.None | Microsoft.ServiceBus.UnifiedSecurityMode.Transport | Microsoft.ServiceBus.UnifiedSecurityMode.Both);
                relaySecurityMode = EndToEndSecurityModeHelper.ToRelaySecurityMode(mode);
            }
            else
            {
                mode = mode & (Microsoft.ServiceBus.UnifiedSecurityMode.Message | Microsoft.ServiceBus.UnifiedSecurityMode.TransportWithMessageCredential);
                relaySecurityMode = EndToEndSecurityModeHelper.ToRelaySecurityMode(mode);
                if (!MessageSecurityOverRelayHttp.TryCreate <NonDualMessageSecurityOverRelayHttp>(sbe, relaySecurityMode == EndToEndSecurityMode.TransportWithMessageCredential, isReliableSessionEnabled, out nonDualMessageSecurityOverRelayHttp))
                {
                    return(false);
                }
            }
            security = new WSHttpRelaySecurity(relaySecurityMode, relayClientAuthenticationType, transportSecurity, nonDualMessageSecurityOverRelayHttp);
            return(true);
        }