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.
Namespace
Grpc.CoreAssembly
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.
Type | Name | Description |
---|---|---|
String | target | Target of the channel. |
ChannelCredentials | credentials | 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.
Type | Name | Description |
---|---|---|
String | target | Target of the channel. |
ChannelCredentials | credentials | 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.
Type | Name | Description |
---|---|---|
String | host | The name or IP address of the host. |
Int32 | port | The port. |
ChannelCredentials | credentials | 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.
Type | Name | Description |
---|---|---|
String | host | The name or IP address of the host. |
Int32 | port | The port. |
ChannelCredentials | credentials | 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.
Type | Description |
---|---|
String |
ShutdownToken
public CancellationToken ShutdownToken { get; }
Returns a token that gets cancelled once ShutdownAsync
is invoked.
Type | Description |
---|---|
CancellationToken |
State
public ChannelState State { get; }
Gets current connectivity state of this channel.
After channel has been shutdown, ChannelState.Shutdown
will be returned.
Type | Description |
---|---|
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.
Type | Name | Description |
---|---|---|
Nullable<DateTime> | deadline | The deadline. |
Type | Description |
---|---|
Task |
CreateCallInvoker()
public override CallInvoker CreateCallInvoker()
Create a new CallInvoker for the channel.
Type | Description |
---|---|
CallInvoker | A new CallInvoker. |
ShutdownAsyncCore()
protected override Task ShutdownAsyncCore()
Provides implementation of a non-virtual public member.
Type | Description |
---|---|
Task |
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).
Type | Name | Description |
---|---|---|
ChannelState | lastObservedState | |
Nullable<DateTime> | deadline |
Type | Description |
---|---|
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.
Type | Name | Description |
---|---|---|
ChannelState | lastObservedState | |
Nullable<DateTime> | deadline |
Type | Description |
---|---|
Task |