WebPubSubServiceClient.SendToConnectionAsync Method

Definition

Overloads

SendToConnectionAsync(String, String, ContentType)

Send message to the specific connection.

SendToConnectionAsync(String, RequestContent, ContentType, RequestContext)

[Protocol Method] Send content inside request body to the specific connection.

  • This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.

SendToConnectionAsync(String, String, ContentType)

Source:
WebPubSubServiceClient.cs

Send message to the specific connection.

public virtual System.Threading.Tasks.Task<Azure.Response> SendToConnectionAsync (string connectionId, string content, Azure.Core.ContentType contentType = default);
abstract member SendToConnectionAsync : string * string * Azure.Core.ContentType -> System.Threading.Tasks.Task<Azure.Response>
override this.SendToConnectionAsync : string * string * Azure.Core.ContentType -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function SendToConnectionAsync (connectionId As String, content As String, Optional contentType As ContentType = Nothing) As Task(Of Response)

Parameters

connectionId
String

The connection Id.

content
String
contentType
ContentType

Defaults to ContentType.PlainText.

Returns

A Response if successful.

Applies to

SendToConnectionAsync(String, RequestContent, ContentType, RequestContext)

Source:
WebPubSubServiceClient.cs

[Protocol Method] Send content inside request body to the specific connection.

  • This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
public virtual System.Threading.Tasks.Task<Azure.Response> SendToConnectionAsync (string connectionId, Azure.Core.RequestContent content, Azure.Core.ContentType contentType, Azure.RequestContext context = default);
abstract member SendToConnectionAsync : string * Azure.Core.RequestContent * Azure.Core.ContentType * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.SendToConnectionAsync : string * Azure.Core.RequestContent * Azure.Core.ContentType * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function SendToConnectionAsync (connectionId As String, content As RequestContent, contentType As ContentType, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

connectionId
String

The connection Id.

content
RequestContent

The content to send as the body of the request.

contentType
ContentType

Upload file type. Allowed values: "application/json" | "application/octet-stream" | "text/plain".

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

connectionId or content is null.

connectionId is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call SendToConnectionAsync.

WebPubSubServiceClient client = new WebPubSubServiceClient("<Endpoint>", "<Hub>");

using RequestContent content = RequestContent.Create(File.OpenRead("<filePath>"));
Response response = await client.SendToConnectionAsync("<connectionId>", content, new ContentType("application/json"));

Console.WriteLine(response.Status);

This sample shows how to call SendToConnectionAsync with all parameters and request content.

WebPubSubServiceClient client = new WebPubSubServiceClient("<Endpoint>", "<Hub>");

using RequestContent content = RequestContent.Create(File.OpenRead("<filePath>"));
Response response = await client.SendToConnectionAsync("<connectionId>", content, new ContentType("application/json"));

Console.WriteLine(response.Status);

Remarks

Schema for Response Error:

{
              code: string,
              message: string,
              target: string,
              details: [ErrorDetail],
              inner: {
                code: string,
                inner: InnerError
              }
            }

Applies to