Show / Hide Table of Contents

    Class Channel

    Represents a gRPC channel. Channels are an abstraction of long-lived connections to remote servers. More client objects can reuse the same channel. Creating a channel is an expensive operation compared to invoking a remote call so in general you should reuse a single channel for as many calls as possible.

    Inheritance
    System.Object
    Channel
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Grpc.Core
    Assembly: Grpc.Core.dll
    Syntax
    public class Channel

    Constructors

    Channel(String, ChannelCredentials)

    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.

    Declaration
    public Channel(string target, ChannelCredentials credentials)
    Parameters
    Type Name Description
    System.String target

    Target of the channel.

    ChannelCredentials credentials

    Credentials to secure the channel.

    Channel(String, ChannelCredentials, IEnumerable<ChannelOption>)

    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.

    Declaration
    public Channel(string target, ChannelCredentials credentials, IEnumerable<ChannelOption> options)
    Parameters
    Type Name Description
    System.String target

    Target of the channel.

    ChannelCredentials credentials

    Credentials to secure the channel.

    System.Collections.Generic.IEnumerable<ChannelOption> options

    Channel options.

    Channel(String, Int32, ChannelCredentials)

    Creates a channel that connects to a specific host and port.

    Declaration
    public Channel(string host, int port, ChannelCredentials credentials)
    Parameters
    Type Name Description
    System.String host

    The name or IP address of the host.

    System.Int32 port

    The port.

    ChannelCredentials credentials

    Credentials to secure the channel.

    Channel(String, Int32, ChannelCredentials, IEnumerable<ChannelOption>)

    Creates a channel that connects to a specific host and port.

    Declaration
    public Channel(string host, int port, ChannelCredentials credentials, IEnumerable<ChannelOption> options)
    Parameters
    Type Name Description
    System.String host

    The name or IP address of the host.

    System.Int32 port

    The port.

    ChannelCredentials credentials

    Credentials to secure the channel.

    System.Collections.Generic.IEnumerable<ChannelOption> options

    Channel options.

    Properties

    ResolvedTarget

    Resolved address of the remote endpoint in URI format.

    Declaration
    public string ResolvedTarget { get; }
    Property Value
    Type Description
    System.String

    ShutdownToken

    Returns a token that gets cancelled once ShutdownAsync is invoked.

    Declaration
    public CancellationToken ShutdownToken { get; }
    Property Value
    Type Description
    System.Threading.CancellationToken

    State

    Gets current connectivity state of this channel. After channel is has been shutdown, ChannelState.Shutdown will be returned.

    Declaration
    public ChannelState State { get; }
    Property Value
    Type Description
    ChannelState

    Target

    The original target used to create the channel.

    Declaration
    public string Target { get; }
    Property Value
    Type Description
    System.String

    Methods

    ConnectAsync(Nullable<DateTime>)

    Allows explicitly requesting channel to connect without starting an RPC. Returned task completes once state Ready was seen. If the deadline is reached, or channel enters the Shutdown state, the task is cancelled. There is no need to call this explicitly unless your use case requires that. Starting an RPC on a new channel will request connection implicitly.

    Declaration
    public Task ConnectAsync(DateTime? deadline = default(DateTime? ))
    Parameters
    Type Name Description
    System.Nullable<System.DateTime> deadline

    The deadline. null indicates no deadline.

    Returns
    Type Description
    System.Threading.Tasks.Task

    ShutdownAsync()

    Shuts down the channel cleanly. It is strongly recommended to shutdown all previously created channels before exiting from the process.

    Declaration
    public Task ShutdownAsync()
    Returns
    Type Description
    System.Threading.Tasks.Task
    Remarks

    This method doesn't wait for all calls on this channel to finish (nor does it explicitly cancel all outstanding calls). It is user's responsibility to make sure all the calls on this channel have finished (successfully or with an error) before shutting down the channel to ensure channel shutdown won't impact the outcome of those remote calls.

    WaitForStateChangedAsync(ChannelState, Nullable<DateTime>)

    Returned tasks completes once channel state has become different from given lastObservedState. If deadline is reached or and error occurs, returned task is cancelled.

    Declaration
    public Task WaitForStateChangedAsync(ChannelState lastObservedState, DateTime? deadline = default(DateTime? ))
    Parameters
    Type Name Description
    ChannelState lastObservedState
    System.Nullable<System.DateTime> deadline
    Returns
    Type Description
    System.Threading.Tasks.Task

    Extension Methods

    ChannelExtensions.Intercept(Channel, Interceptor)
    ChannelExtensions.Intercept(Channel, Interceptor[])
    ChannelExtensions.Intercept(Channel, Func<Metadata, Metadata>)
    Back to top Generated by DocFX