Exemplo n.º 1
0
 /// <summary>
 /// Creates a channel.
 /// </summary>
 public Channel(string target, Credentials credentials = null, ChannelArgs channelArgs = null)
 {
     using (ChannelArgsSafeHandle nativeChannelArgs = CreateNativeChannelArgs(channelArgs))
     {
         if (credentials != null)
         {
             using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials())
             {
                 this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs);
             }
         }
         else
         {
             this.handle = ChannelSafeHandle.Create(target, nativeChannelArgs);
         }
     }
     this.target = GetOverridenTarget(target, channelArgs);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a channel that connects to a specific host.
 /// Port will default to 80 for an unsecure channel and to 443 a secure channel.
 /// </summary>
 /// <param name="host">The DNS name of IP address of the host.</param>
 /// <param name="credentials">Optional credentials to create a secure channel.</param>
 /// <param name="options">Channel options.</param>
 public Channel(string host, Credentials credentials = null, IEnumerable<ChannelOption> options = null)
 {
     using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(options))
     {
         if (credentials != null)
         {
             using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials())
             {
                 this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, host, nativeChannelArgs);
             }
         }
         else
         {
             this.handle = ChannelSafeHandle.Create(host, nativeChannelArgs);
         }
     }
     this.target = GetOverridenTarget(host, options);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a channel that connects to a specific host.
        /// Port will default to 80 for an unsecure channel and to 443 a secure channel.
        /// </summary>
        /// <param name="host">The DNS name of IP address of the host.</param>
        /// <param name="credentials">Credentials to secure the channel.</param>
        /// <param name="options">Channel options.</param>
        public Channel(string host, Credentials credentials, IEnumerable<ChannelOption> options = null)
        {
            this.environment = GrpcEnvironment.GetInstance();
            this.options = options != null ? new List<ChannelOption>(options) : new List<ChannelOption>();

            EnsureUserAgentChannelOption(this.options);
            using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials())
            using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options))
            {
                if (nativeCredentials != null)
                {
                    this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, host, nativeChannelArgs);
                }
                else
                {
                    this.handle = ChannelSafeHandle.CreateInsecure(host, nativeChannelArgs);
                }
            }
            this.target = GetOverridenTarget(host, this.options);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a channel that connects to a specific host.
        /// Port will default to 80 for an unsecure channel and to 443 for a secure channel.
        /// </summary>
        /// <param name="target">Target of the channel.</param>
        /// <param name="credentials">Credentials to secure the channel.</param>
        /// <param name="options">Channel options.</param>
        public Channel(string target, Credentials credentials, IEnumerable<ChannelOption> options = null)
        {
            this.target = Preconditions.CheckNotNull(target, "target");
            this.environment = GrpcEnvironment.AddRef();
            this.options = options != null ? new List<ChannelOption>(options) : new List<ChannelOption>();

            EnsureUserAgentChannelOption(this.options);
            using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials())
            using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options))
            {
                if (nativeCredentials != null)
                {
                    this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs);
                }
                else
                {
                    this.handle = ChannelSafeHandle.CreateInsecure(target, nativeChannelArgs);
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a channel that connects to a specific host and port.
 /// </summary>
 /// <param name="host">DNS name or IP address</param>
 /// <param name="port">the port</param>
 /// <param name="credentials">Credentials to secure the channel.</param>
 /// <param name="options">Channel options.</param>
 public Channel(string host, int port, Credentials credentials, IEnumerable<ChannelOption> options = null)
     : this(string.Format("{0}:{1}", host, port), credentials, options)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a channel that connects to a specific host and port.
 /// </summary>
 /// <param name="host">DNS name or IP address</param>
 /// <param name="port">the port</param>
 /// <param name="credentials">Optional credentials to create a secure channel.</param>
 /// <param name="options">Channel options.</param>
 public Channel(string host, int port, Credentials credentials = null, IEnumerable <ChannelOption> options = null) :
     this(string.Format("{0}:{1}", host, port), credentials, options)
 {
 }