HubConnection Class

Definition

A connection used to invoke hub methods on a SignalR Server.

public ref class HubConnection
public class HubConnection
public class HubConnection : IAsyncDisposable
type HubConnection = class
type HubConnection = class
    interface IAsyncDisposable
Public Class HubConnection
Public Class HubConnection
Implements IAsyncDisposable
Inheritance
HubConnection
Implements

Remarks

A HubConnection should be created using HubConnectionBuilder. Before hub methods can be invoked the connection must be started using StartAsync(CancellationToken). Clean up a connection using StopAsync(CancellationToken) or DisposeAsync().

Constructors

HubConnection(IConnectionFactory, IHubProtocol, EndPoint, IServiceProvider, ILoggerFactory)

Initializes a new instance of the HubConnection class.

HubConnection(IConnectionFactory, IHubProtocol, EndPoint, IServiceProvider, ILoggerFactory, IRetryPolicy)

Initializes a new instance of the HubConnection class.

HubConnection(IConnectionFactory, IHubProtocol, ILoggerFactory)

Initializes a new instance of the HubConnection class.

HubConnection(IConnectionFactory, IHubProtocol, IServiceProvider, ILoggerFactory)

Initializes a new instance of the HubConnection class.

Fields

DefaultHandshakeTimeout

The default timeout which specifies how long to wait for the handshake to respond before closing the connection. Default is 15 seconds.

DefaultKeepAliveInterval

The default interval that the client will send keep alive messages to let the server know to not close the connection. Default is 15 second interval.

DefaultServerTimeout

The default timeout which specifies how long to wait for a message before closing the connection. Default is 30 seconds.

Properties

ConnectionId

Gets the connection's current Id. This value will be cleared when the connection is stopped and will have a new value every time the connection is (re)established. This value will be null if the negotiation step is skipped via HttpConnectionOptions or if the WebSockets transport is explicitly specified because the client skips negotiation in that case as well.

HandshakeTimeout

Gets or sets the timeout for the initial handshake.

KeepAliveInterval

Gets or sets the interval at which the client sends ping messages.

ServerTimeout

Gets or sets the server timeout interval for the connection.

State

Indicates the state of the HubConnection to the server.

Methods

DisposeAsync()

Disposes the HubConnection.

InvokeCoreAsync(String, Type, Object[], CancellationToken)

Invokes a hub method on the server using the specified method name, return type and arguments.

On(String, Type[], Func<Object[],Object,Task<Object>>, Object)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On(String, Type[], Func<Object[],Object,Task>, Object)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Remove(String)

Removes all handlers associated with the method with the specified method name.

ResetSendPing()
ResetTimeout()
SendCoreAsync(String, Object[], CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

StartAsync(CancellationToken)

Starts a connection to the server.

StopAsync(CancellationToken)

Stops a connection to the server.

StreamAsChannelCoreAsync(String, Type, Object[], CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsyncCore<TResult>(String, Object[], CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

Events

Closed

Occurs when the connection is closed. The connection could be closed due to an error or due to either the server or client intentionally closing the connection without error.

Reconnected

Occurs when the HubConnection successfully reconnects after losing its underlying connection.

Reconnecting

Occurs when the HubConnection starts reconnecting after losing its underlying connection.

Extension Methods

InvokeAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync(HubConnection, String, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and argument.

InvokeAsync(HubConnection, String, CancellationToken)

Invokes a hub method on the server using the specified method name.

InvokeAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeAsync<TResult>(HubConnection, String, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and argument.

InvokeAsync<TResult>(HubConnection, String, CancellationToken)

Invokes a hub method on the server using the specified method name.

InvokeCoreAsync(HubConnection, String, Object[], CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

InvokeCoreAsync<TResult>(HubConnection, String, Object[], CancellationToken)

Invokes a hub method on the server using the specified method name and arguments.

On(HubConnection, String, Action)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On(HubConnection, String, Func<Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On(HubConnection, String, Type[], Func<Object[],Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1>(HubConnection, String, Action<T1>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1>(HubConnection, String, Func<T1,Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<TResult>(HubConnection, String, Func<TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<TResult>(HubConnection, String, Func<Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<TResult>(HubConnection, String, Type[], Func<Object[],Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2>(HubConnection, String, Action<T1,T2>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2>(HubConnection, String, Func<T1,T2,Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,TResult>(HubConnection, String, Func<T1,TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,TResult>(HubConnection, String, Func<T1,Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3>(HubConnection, String, Action<T1,T2,T3>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3>(HubConnection, String, Func<T1,T2,T3,Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,TResult>(HubConnection, String, Func<T1,T2,TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,TResult>(HubConnection, String, Func<T1,T2,Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4>(HubConnection, String, Action<T1,T2,T3,T4>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4>(HubConnection, String, Func<T1,T2,T3,T4,Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,TResult>(HubConnection, String, Func<T1,T2,T3,TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,TResult>(HubConnection, String, Func<T1,T2,T3,Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5>(HubConnection, String, Action<T1,T2,T3,T4,T5>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4,T5>(HubConnection, String, Func<T1,T2,T3,T4,T5,Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4,TResult>(HubConnection, String, Func<T1,T2,T3,T4,TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,TResult>(HubConnection, String, Func<T1,T2,T3,T4,Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5,T6>(HubConnection, String, Action<T1,T2,T3,T4,T5,T6>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4,T5,T6>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4,T5,TResult>(HubConnection, String, Func<T1,T2,T3,T4,T5,TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5,TResult>(HubConnection, String, Func<T1,T2,T3,T4,T5,Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5,T6,T7>(HubConnection, String, Action<T1,T2,T3,T4,T5,T6,T7>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4,T5,T6,T7>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,T7,Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4,T5,T6,TResult>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5,T6,TResult>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5,T6,T7,T8>(HubConnection, String, Action<T1,T2,T3,T4,T5,T6,T7,T8>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4,T5,T6,T7,T8>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,T7,T8,Task>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

On<T1,T2,T3,T4,T5,T6,T7,TResult>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,T7,TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5,T6,T7,TResult>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,T7,Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5,T6,T7,T8,TResult>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,T7,T8,TResult>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

On<T1,T2,T3,T4,T5,T6,T7,T8,TResult>(HubConnection, String, Func<T1,T2,T3,T4,T5,T6,T7,T8,Task<TResult>>)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Returns value returned by handler to server if the server requests a result.

SendAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, Object, CancellationToken)

Invokes a hub method on the server using the specified method name and argument. Does not wait for a response from the receiver.

SendAsync(HubConnection, String, CancellationToken)

Invokes a hub method on the server using the specified method name. Does not wait for a response from the receiver.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsChannelAsync<TResult>(HubConnection, String, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsChannelAsync<TResult>(HubConnection, String, CancellationToken)

Invokes a streaming hub method on the server using the specified method name and return type.

StreamAsChannelCoreAsync<TResult>(HubConnection, String, Object[], CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and arguments.

StreamAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, Object, CancellationToken)

Invokes a streaming hub method on the server using the specified method name, return type and argument.

StreamAsync<TResult>(HubConnection, String, CancellationToken)

Invokes a streaming hub method on the server using the specified method name and return type.

Applies to