Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configuration doc #7031

Closed

Conversation

rachelappel
Copy link
Contributor

@rachelappel rachelappel commented Jun 13, 2018

fixes #6599
The PR at #6852 kept erroring when pushing despite fixing merge messages, so I moved it here rather than continue to fight with it for no reason.

Internal review

Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find the internal review link :(

## JSON/MessagePack Serialization Options

ASP.NET Core SignalR supports two protocols for encoding messages, JSON and MessagePack. Each protocol has configuration options that can be used to configure serialization.
JSON Serialization Options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"###"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 #'s are a H3 subheading (these under messagepack). Move to H2 (##)?

ASP.NET Core SignalR supports two protocols for encoding messages, JSON and MessagePack. Each protocol has configuration options that can be used to configure serialization.
JSON Serialization Options

JSON serialization can be configured on both the Server and .NET Client by providing a delegate to the AddJsonHubProtocol method. The options object received by that delegate has a PayloadSerializedSettings which is a JSON.NET JsonSerializerSettings object that can be used to configure serialization of arguments and return values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing some code markdown and fullstop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON serialization can be configured on both the Server and .NET Client.

[import snippet]
In the preceding code,


JSON serialization can be configured on both the Server and .NET Client by providing a delegate to the AddJsonHubProtocol method. The options object received by that delegate has a PayloadSerializedSettings which is a JSON.NET JsonSerializerSettings object that can be used to configure serialization of arguments and return values

On the server, add `AddJsonHubProtocol` to the `AddSignalR` call in `ConfigureServices`. Use PascalCase property names instead of the default camelCase names. See the [JSON.NET Documentation](https://www.newtonsoft.com/json/help/html/Introduction.htm) for more details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Use PascalCase property names instead of the default camelCase names."
This sounds like we're telling them to use Pascal always

options.PayloadSerializerSettings.ContractResolver =
new DefaultContractResolver();
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra "}"
Move whole code snippet one tab left

using Microsoft.Extensions.DependencyInjection;

// When constructing your connection:
var connection = new HubConnectionBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove ";"

options.AccessTokenProvider = async () => {
// Get access token and return it.
};
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ";"

options.Headers["Foo"] = "Bar";
options.Cookies.Add(new Cookie(...));
options.ClientCertificates.Add(...);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ";"

.withUrl("url")
.build();

// Sets the transport type. Transport types are defined in preceding table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot the table?

.build();
```

> ![NOTE]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[!NOTE]

| `transport` | Specific transport the client should use, or an `ITransport` implementation for a custom transport. |
| `accessTokenFactory` | Called for each HTTP request to set the authorization header or for WebSockets to set the `access_token` query string value. |
| `logMessageContent` | Log the message content when sending and receiving. Disabled by default. |
| `skipNegotiation` | Only use this when `HttpTransportType.WebSockets` is specified. It skips the negotiation step when it not necessary. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"It skips the negotiation step when it not necessary." =>
"It skips the negotiation step when it isn't necessary."

@rachelappel
Copy link
Contributor Author

Closing/reopening to force a build to get review link

@rachelappel rachelappel reopened this Jun 14, 2018
@Rick-Anderson
Copy link
Contributor

@BrennanConroy Internal review is working.

@Rick-Anderson
Copy link
Contributor

@rachelappel

  • Fix all API links
  • All APIs referenced need first occurrence to be a link to the API
  • Replace all copy/paste snippets with imported snippets


## JSON/MessagePack Serialization Options

ASP.NET Core SignalR supports two protocols for encoding messages, JSON and MessagePack. Each protocol has configuration options that can be used to configure serialization.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about
Each protocol has serialization configuration options .

Linke MessagePack to https://msgpack.org/index.html or other appropriate


# ASP.NET Core SignalR configuration

## JSON/MessagePack Serialization Options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sentence case

ASP.NET Core SignalR supports two protocols for encoding messages, JSON and MessagePack. Each protocol has configuration options that can be used to configure serialization.
JSON Serialization Options

JSON serialization can be configured on both the Server and .NET Client by providing a delegate to the AddJsonHubProtocol method. The options object received by that delegate has a PayloadSerializedSettings which is a JSON.NET JsonSerializerSettings object that can be used to configure serialization of arguments and return values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options object received by that delegate has a PayloadSerializedSettings which is a JSON.NET JsonSer
too long, split up.

AddJsonHubProtocol
Code fence all code. Ditto for PayloadSerializedSettings and JsonSerializerSettings

| Option | Description |
| ------ | ----------- |
| `HandshakeTimeout` | If the client doesn't send an initial handshake message within this time interval, the connection will be closed |
| `KeepAliveInterval` | If the server hasn't sent a message within this interval, a ping message will is sent automatically to keep the connection open |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will is

| `HandshakeTimeout` | If the client doesn't send an initial handshake message within this time interval, the connection will be closed |
| `KeepAliveInterval` | If the server hasn't sent a message within this interval, a ping message will is sent automatically to keep the connection open |
| `SupportedProtocols` | Protocols supported by this hub. By default, all protocols registered on the server are allowed, but protocols can be removed from this list to disable specific protocols for individual hubs. |
| `EnableDetailedErrors` | If true, sends detailed error messages to the client when exceptions occur. This may contain sensitive data and is `false` by default |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid this
The detailed error messages may ...


### HttpConnectionDispatcherOptions

Options related to the transport layer. Use these to restrict the transports that can be used by SignalR clients, as well as to configure advanced settings related to memory buffer management. These options are configured by passing a delegate to `MapHub<T>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options related to the transport layer.

That doesn't make sense by itself. SHould it be

HttpConnectionDispatcherOptions - Options related to the transport layer.

| Cookies | Cookies to be sent with each HTTP request. |
| ClientCertificates | TLS client certificates to send when connecting over HTTP (not supported in Xamarin) |

The following code samples demonstrate the C# setting connection options with the `HubConnectionBuilder`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code sets connection options with the HubConnectionBuilder:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
```

### HttpConnectionDispatcherOptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append Options related to the transport layer ???


### HttpConnectionDispatcherOptions

Options related to the transport layer. Use these to restrict the transports that can be used by SignalR clients, as well as to configure advanced settings related to memory buffer management. These options are configured by passing a delegate to `MapHub<T>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is these?


| Option | Description |
| ------ | ----------- |
| `ApplicationMaxBufferSize` | The maximum number of bytes the connection (transport) can buffer when invoking methods from the client, before blocking and waiting for the application to consume enough bytes to allow writing again. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to split up long sentence.

Copy link
Contributor

@analogrelay analogrelay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments. Still working through it


[!code-csharp[Startup config](configuration/sample/config-startup.cs?range=1-5)]

The preceding code adds add `AddJsonHubProtocol` to the [AddSignalR](/dotnet/api/microsoft.extensions.dependencyinjection.signalrdependencyinjectionextensions.addsignalr#Microsoft_Extensions_DependencyInjection_SignalRDependencyInjectionExtensions_AddSignalR_Microsoft_Extensions_DependencyInjection_IServiceCollection_) call in [ConfigureServices](/dotnet/api/microsoft.aspnetcore.hosting.istartup.configureservices#Microsoft_AspNetCore_Hosting_IStartup_ConfigureServices_Microsoft_Extensions_DependencyInjection_IServiceCollection_). Then the code provides a delegate to the `AddJsonHubProtocol` method. The `options` object received by that delegate has a `PayloadSerializedSettings`. The `PayloadSerializedSettings` is a JSON.NET [JsonSerializerSettings](/dotnet/api/microsoft.aspnetcore.mvc.formatters.jsonserializersettingsprovider object that can be used to configure serialization of arguments and return values. See the [JSON.NET Documentation](https://www.newtonsoft.com/json/help/html/Introduction.htm) for more details.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording here seems a bit awkward. What about moving it above the example:

JSON serialization can be configured on the server using the AddJsonProtocol extension method. The AddJsonProtocol method takes a delegate that receives an options object. The PayloadSerializerSettings property on that object is a JSON.NET JsonSerializerSettings object that can be used to configure serialization of arguments and return values. See the JSON.NET Documentation for more details.

As an example, you can configure the serializer to use PascalCase names instead of the default camelCase names using the following code:

[example]

In the .NET client, the same AddJsonHubProtocol extension method exists on HubConnectionBuilder. The Microsoft.Extensions.DependencyInjection namespace must be imported to resolve the extension method:

[example]

The preceding code adds add `AddJsonHubProtocol` to the [AddSignalR](/dotnet/api/microsoft.extensions.dependencyinjection.signalrdependencyinjectionextensions.addsignalr#Microsoft_Extensions_DependencyInjection_SignalRDependencyInjectionExtensions_AddSignalR_Microsoft_Extensions_DependencyInjection_IServiceCollection_) call in [ConfigureServices](/dotnet/api/microsoft.aspnetcore.hosting.istartup.configureservices#Microsoft_AspNetCore_Hosting_IStartup_ConfigureServices_Microsoft_Extensions_DependencyInjection_IServiceCollection_). Then the code provides a delegate to the `AddJsonHubProtocol` method. The `options` object received by that delegate has a `PayloadSerializedSettings`. The `PayloadSerializedSettings` is a JSON.NET [JsonSerializerSettings](/dotnet/api/microsoft.aspnetcore.mvc.formatters.jsonserializersettingsprovider object that can be used to configure serialization of arguments and return values. See the [JSON.NET Documentation](https://www.newtonsoft.com/json/help/html/Introduction.htm) for more details.

> [!NOTE]
> It's possible to use PascalCase property names instead of the default camelCase names.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems awkward. There are many different settings and while this is a common one, I don't think it should be called out as a NOTE. In my above comment, I suggested just working it in to the example description. I think that's a little cleaner.


### Configure [HubOptions](/dotnet/api/microsoft.aspnetcore.signalr.huboptions) for SignalR

The following table describes the `HubOptions` options for configuring the hub:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for configuring the a hub

| `SupportedProtocols` | Protocols supported by this hub. By default, all protocols registered on the server are allowed, but protocols can be removed from this list to disable specific protocols for individual hubs. |
| `EnableDetailedErrors` | If true, sends detailed error messages to the client when exceptions occur. The detailed error messages may contain sensitive data, and are `false` by default. |

The `HubOptions` are configured in the `ConfigureServices` method of the `Startup` class, as shown in the following code sample:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest:

Options can be configured for all hubs by providing an options delegate to the AddSignalR call in ConfigureServices


[!code-csharp[Startup](configuration/sample/config-startup.cs?range=7-14)]

Strongly-typed [HubOptions<T>](/dotnet/api/microsoft.aspnetcore.signalr.huboptions-1) are as follows:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest:

Options for a single hub override the global options provided in AddSignalR and can be configured using AddHubOptions<T>:

@rachelappel rachelappel force-pushed the rachelap/signalr-configuration branch from edbc7f1 to 79f0c5e Compare June 18, 2018 19:18
> [!NOTE]
> It's not possible to configure JSON or MessagePack serialization in the JavaScript client at this time.

### Configure [HubOptions](/dotnet/api/microsoft.aspnetcore.signalr.huboptions) for SignalR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make all these headers a little more consistent. How about we remove the type names from the headers, and leave those for the prose below.

Also, I think we can just merge this with the next section (HttpConnectionDispatcherOptions) as a "Configuring Server Options" section. The section below on the Client has multiple types and I think it works fine there.


Items in the table marked with an asterisk (*) are specific to WebSockets.

### HubConnectionBuilder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Configuring Client Options"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section looks really rough right now. I think we should split it into two, with one for .NET and one for JavaScript. There will be some duplication, but I think that's OK.

In each section, I think we should list the properties on the relevant object (JS: https://github.com/aspnet/SignalR/blob/dev/clients/ts/signalr/src/IHttpConnectionOptions.ts, C#: https://github.com/aspnet/SignalR/blob/dev/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnectionOptions.cs) with the descriptions we've got here. Code samples can come afterwards, illustrating some of the scenarios.


### HubConnectionBuilder

The [HubConnectionBuilder](/dotnet/api/microsoft.aspnetcore.signalr.client.hubconnectionbuilder) API is available for both C# and TypeScript clients.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript JavaScript

The client is written in TypeScript and includes a full set of "typings" files to make it easier to use from TypeScript, but that's just an implementation detail. The client works on any JavaScript environment and you can use plain JavaScript to interact with it, so it's a "JavaScript client"

| `WebSockets`* | Gets the WebSockets options object. |
| `CloseTimeout`* | TimeSpan to set how long to wait for a clean WebSocket close when connection is being terminated. |
| `SubProtocolSelector`* | A delegate the hub calls and passes a list of `Sec-WebSocket-Protocol` values from the request header. A delegate returns the chosen `Sec-WebSocket-Protocol`. |
| `AccessTokenProvider`* | A delegate that is called to get an access token. The token is applied as an HTTP Bearer Authentication header. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First: AccessTokenProvider isn't a property on HttpConnectionDispatcherOptions. Just strike this row.

Also: It's not quite clear that CloseTimeout, and SubProtocolSelector are properties on the WebSocketOptions object, not HttpConnectionDispatcherOptions. Perhaps a separate table? Or write them as WebSockets.CloseTimeout?


Items in the table marked with an asterisk (*) are specific to WebSockets.

## Configure client options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the client options section needs a bit of a rework. The headers don't match with the tables and the code snippets are a bit rough. I'll sketch something up.

@analogrelay
Copy link
Contributor

Replace all copy/paste snippets with imported snippets

@Rick-Anderson Can you clarify the expected pattern here? In most of the other docs it looks like inline snippets are used when the example is illustrative but not part of a fully-functional sample and imported snippets are used when the example is part of a fully-functional sample. There isn't a sample associated with this document so I'd expect to use mostly inline snippets in this document.

title: ASP.NET Core SignalR configuration
author: rachelappel
description: Configure ASP.NET Core SignalR Apps
manager: wpickett
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the following metadata fields:

  1. manager
  2. ms.prod
  3. ms.technology
  4. ms.topic

These are defined in docfx.json now.


[!code-csharp[HubConnectionBuilder](configuration/sample/addhubjsonprotocol.cs)]

### MessagePack Serialization Options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serialization Options --> serialization options

@analogrelay
Copy link
Contributor

I reworked the client options section, but I realized the original branch is in a fork so I can't easily just push some additional changes :). The easiest thing to do here may just be to open a new PR (again 😝) from my branch now.

@rachelappel
Copy link
Contributor Author

@anurse Go for it, remember to tag us. :D I'll hold off on any changes on my side until you do that.

scottaddie pushed a commit that referenced this pull request Jun 26, 2018
As discussed #7031 (comment) I made some changes and decided to just open a new PR to get things cleared up.

[Internal Review URL](https://review.docs.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-2.1&branch=pr-en-us-7199)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Topic: SignalR Configuration
5 participants