Class Channel

public class Channel : ChannelBase

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

Object > ChannelBase > Channel

Namespace

Grpc.Core

Assembly

Grpc.Core.dll

Constructors

Channel(String, ChannelCredentials)

public Channel(string target, ChannelCredentials credentials)

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.

Parameters
TypeNameDescription
Stringtarget

Target of the channel.

ChannelCredentialscredentials

Credentials to secure the channel.

Channel(String, ChannelCredentials, IEnumerable<ChannelOption>)

public Channel(string target, ChannelCredentials credentials, IEnumerable<ChannelOption> options)

Creates a channel that connects to a specific host. Port will default to 80 for an unsecure channel or to 443 for a secure channel.

Parameters
TypeNameDescription
Stringtarget

Target of the channel.

ChannelCredentialscredentials

Credentials to secure the channel.

IEnumerable<ChannelOption>options

Channel options.

Channel(String, Int32, ChannelCredentials)

public Channel(string host, int port, ChannelCredentials credentials)

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

Parameters
TypeNameDescription
Stringhost

The name or IP address of the host.

Int32port

The port.

ChannelCredentialscredentials

Credentials to secure the channel.

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

public Channel(string host, int port, ChannelCredentials credentials, IEnumerable<ChannelOption> options)

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

Parameters
TypeNameDescription
Stringhost

The name or IP address of the host.

Int32port

The port.

ChannelCredentialscredentials

Credentials to secure the channel.

IEnumerable<ChannelOption>options

Channel options.

Properties

ResolvedTarget

public string ResolvedTarget { get; }

Resolved address of the remote endpoint in URI format.

Property Value
TypeDescription
String

ShutdownToken

public CancellationToken ShutdownToken { get; }

Returns a token that gets cancelled once ShutdownAsync is invoked.

Property Value
TypeDescription
CancellationToken

State

public ChannelState State { get; }

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

Property Value
TypeDescription
ChannelState

Methods

ConnectAsync(Nullable<DateTime>)

public Task ConnectAsync(DateTime? deadline = null)

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.

Parameter
TypeNameDescription
Nullable<DateTime>deadline

The deadline. null indicates no deadline.

Returns
TypeDescription
Task

CreateCallInvoker()

public override CallInvoker CreateCallInvoker()

Create a new CallInvoker for the channel.

Returns
TypeDescription
CallInvoker

A new CallInvoker.

Overrides

ShutdownAsyncCore()

protected override Task ShutdownAsyncCore()

Provides implementation of a non-virtual public member.

Returns
TypeDescription
Task
Overrides

TryWaitForStateChangedAsync(ChannelState, Nullable<DateTime>)

public Task<bool> TryWaitForStateChangedAsync(ChannelState lastObservedState, DateTime? deadline = null)

Returned tasks completes once channel state has become different from given lastObservedState (true is returned) or if the wait has timed out (false is returned).

Parameters
TypeNameDescription
ChannelStatelastObservedState
Nullable<DateTime>deadline
Returns
TypeDescription
Task<Boolean>

WaitForStateChangedAsync(ChannelState, Nullable<DateTime>)

public Task WaitForStateChangedAsync(ChannelState lastObservedState, DateTime? deadline = null)

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

Parameters
TypeNameDescription
ChannelStatelastObservedState
Nullable<DateTime>deadline
Returns
TypeDescription
Task