You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-signalr/signalr-quickstart-azure-functions-csharp.md
+33-36Lines changed: 33 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,41 @@
1
1
---
2
2
title: "Azure SignalR Service serverless quickstart - C#"
3
-
description: "A quickstart for using Azure SignalR Service and Azure Functions to create an App showing GitHub star count using C#."
3
+
description: "A quickstart for using Azure SignalR Service and Azure Functions to create an app showing GitHub star count using C#."
4
4
author: vicancy
5
5
ms.service: signalr
6
6
ms.devlang: csharp
7
7
ms.topic: quickstart
8
8
ms.custom: devx-track-csharp, mode-other
9
-
ms.date: 06/09/2021
9
+
ms.date: 03/30/2022
10
10
ms.author: lianwei
11
11
---
12
12
13
-
# Quickstart: Create an App showing GitHub star count with Azure Functions and SignalR Service via C#
13
+
# Quickstart: Create an app showing GitHub star count with Azure Functions and SignalR Service via C#
14
14
15
-
Azure SignalR Service lets you easily add real-time functionality to your application. Azure Functions is a serverless platform that lets you run your code without managing any infrastructure. In this quickstart, learn how to use SignalR Service and Azure Functions to build a serverless application with C# to broadcast messages to clients.
15
+
In this article, you'll learn how to use SignalR Service and Azure Functions to build a serverless application with C# to broadcast messages to clients.
16
16
17
17
> [!NOTE]
18
-
> You can get all codes mentioned in the article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/QuickStartServerless/csharp)
18
+
> You can get the code mentioned in this article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/QuickStartServerless/csharp).
19
19
20
20
## Prerequisites
21
21
22
-
If you don't already have Visual Studio Code installed, you can download and use it for free(https://code.visualstudio.com/Download).
22
+
The following prerequisites are needed for this quickstart:
23
23
24
-
You may also run this tutorial on the command line (macOS, Windows, or Linux) using the [Azure Functions Core Tools)](../azure-functions/functions-run-local.md?tabs=windows%2Ccsharp%2Cbash#v2). Also the [.NET Core SDK](https://dotnet.microsoft.com/download), and your favorite code editor.
24
+
- Visual Studio Code, or other code editor. If you don't already have Visual Studio Code installed, [download Visual Studio Code here](https://code.visualstudio.com/Download).
25
+
- An Azure subscription. If you don't have an Azure subscription, [create one for free](https://azure.microsoft.com/free/dotnet) before you begin.
2. After you initialize a project. Create a new file with name *Function.cs*. Add the following code to *Function.cs*.
48
+
1. Using your code editor, create a new file with the name *Function.cs*. Add the following code to *Function.cs*:
53
49
54
50
```csharp
55
51
using System;
@@ -126,10 +122,14 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
126
122
}
127
123
}
128
124
```
129
-
These codes have three functions. The `Index` is used to get a website as client. The `Negotiate` is used for client to get access token. The `Broadcast` is periodically
130
-
get star count from GitHub and broadcast messages to all clients.
131
125
132
-
3. The client interface of this sample is a web page. Considered we read HTML content from `content/index.html`in`GetHomePage` function, create a new file `index.html`in`content` directory under project root folder. And copy the following content.
126
+
The code in*Function.cs* has three functions:
127
+
- `GetHomePage` is used to get a website as client.
128
+
- `Negotiate` is used by the client to get an access token.
129
+
- `Broadcast` is periodically called to get the star count from GitHub and then broadcast messages to all clients.
130
+
131
+
1. The client interface for this sample is a web page. We render the web page using the `GetHomePage`functionby reading HTML content from file *content/index.html*. Now let's create this *index.html* under the `content` subdirectory with the following content:
132
+
133
133
```html
134
134
<html>
135
135
@@ -156,7 +156,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
156
156
</html>
157
157
```
158
158
159
-
4. Update your `*.csproj` to make the content page in build output folder.
159
+
1. Update your `*.csproj` to make the content page in the build output folder.
160
160
161
161
```html
162
162
<ItemGroup>
@@ -166,44 +166,41 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
166
166
</ItemGroup>
167
167
```
168
168
169
-
5. It's almost done now. The last step is to set a connection string of the SignalR Service to Azure Function settings.
169
+
1. It's almost done now. The last step is to set a connection string of the SignalR Service to Azure Function settings.
170
170
171
-
1. In the browser where the Azure portal is opened, confirm the SignalR Service instance you deployed earlier was successfully created by searching for its name in the search box at the top of the portal. Select the instance to open it.
171
+
1. Confirm the SignalR Service instance was successfully created by searching for its name in the search box at the top of the portal. Select the instance to open it.
172
172
173
173

174
174
175
-
2. Select **Keys** to view the connection strings for the SignalR Service instance.
175
+
1. Select **Keys** to view the connection strings for the SignalR Service instance.
176
176
177
177

178
178
179
-
3. Copy the primary connection string. And execute the command below.
179
+
1. Copy the primary connection string, and then run the following command:
After Azure Function running locally. Use your browser to visit `http://localhost:7071/api/index` and you can see the current star count. And if you star or unstar in the GitHub, you will get a star count refreshing every few seconds.
191
+
After the Azure function is running locally, open `http://localhost:7071/api/index` and you can see the current star count. If you star or unstar in the GitHub, you'll get a star count refreshing every few seconds.
192
192
193
193
> [!NOTE]
194
-
> SignalR binding needs Azure Storage, but you can use local storage emulator when the Function is running locally.
195
-
> If you got some error like `There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid.` You need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md)
196
-
197
-
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qscsharp)
194
+
> SignalR binding needs Azure Storage, but you can use a local storage emulator when the functionis running locally.
195
+
> If you got the error `There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid.` You need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md)
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qspython).
202
200
203
201
## Next steps
204
202
205
-
In this quickstart, you built and ran a real-time serverless application in local. Learn more how to use SignalR Service bindings for Azure Functions.
206
-
Next, learn more about how to bi-directional communicating between clients and Azure Function with SignalR Service.
203
+
In this quickstart, you built and ran a real-time serverless application locally. Next, learn more about bi-directional communication between clients and Azure Functions with Azure SignalR Service.
207
204
208
205
> [!div class="nextstepaction"]
209
206
> [SignalR Service bindings for Azure Functions](../azure-functions/functions-bindings-signalr-service.md)
0 commit comments