Skip to content

Commit 4c61449

Browse files
Merge pull request #193727 from grminch/signalr-c-i
Finish editing az functions c#
2 parents d10ce23 + 4ee66ce commit 4c61449

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

articles/azure-signalr/signalr-quickstart-azure-functions-csharp.md

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
11
---
22
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#."
44
author: vicancy
55
ms.service: signalr
66
ms.devlang: csharp
77
ms.topic: quickstart
88
ms.custom: devx-track-csharp, mode-other
9-
ms.date: 06/09/2021
9+
ms.date: 03/30/2022
1010
ms.author: lianwei
1111
---
1212

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#
1414

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.
1616

1717
> [!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).
1919
2020
## Prerequisites
2121

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:
2323

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.
26+
- [Azure Functions Core Tools](../azure-functions/functions-run-local.md?tabs=windows%2Ccsharp%2Cbash#v2)
27+
- [.NET Core SDK](https://dotnet.microsoft.com/download)
2528

26-
If you don't have an Azure subscription, [create one for free](https://azure.microsoft.com/free/dotnet) before you begin.
27-
28-
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qscsharp).
29-
30-
## Log in to Azure and create SignalR Service instance
31-
32-
Sign in to the Azure portal at <https://portal.azure.com/> with your Azure account.
33-
34-
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qscsharp).
29+
## Create an Azure SignalR Service instance
3530

3631
[!INCLUDE [Create instance](includes/signalr-quickstart-create-instance.md)]
3732

38-
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qscsharp).
39-
4033
## Setup and run the Azure Function locally
4134

42-
1. Make sure you have Azure Function Core Tools installed. And create an empty directory and navigate to the directory with command line.
35+
You'll need the Azure Functions Core Tools for this step.
36+
37+
1. Create an empty directory and change to the directory with the command line.
38+
1. Initialize a new project.
4339

4440
```bash
4541
# Initialize a function project
@@ -49,7 +45,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
4945
dotnet add package Microsoft.Azure.WebJobs.Extensions.SignalRService
5046
```
5147

52-
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*:
5349

5450
```csharp
5551
using System;
@@ -126,10 +122,14 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
126122
}
127123
}
128124
```
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.
131125
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` function by reading HTML content from file *content/index.html*. Now let's create this *index.html* under the `content` subdirectory with the following content:
132+
133133
```html
134134
<html>
135135
@@ -156,7 +156,7 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
156156
</html>
157157
```
158158
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.
160160
161161
```html
162162
<ItemGroup>
@@ -166,44 +166,41 @@ Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.
166166
</ItemGroup>
167167
```
168168
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.
170170
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.
172172
173173
![Search for the SignalR Service instance](media/signalr-quickstart-azure-functions-csharp/signalr-quickstart-search-instance.png)
174174
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.
176176
177177
![Screenshot that highlights the primary connection string.](media/signalr-quickstart-azure-functions-javascript/signalr-quickstart-keys.png)
178178
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:
180180
181181
```bash
182182
func settings add AzureSignalRConnectionString "<signalr-connection-string>"
183183
```
184184
185-
6. Run the Azure Function in local:
185+
1. Run the Azure function locally:
186186
187187
```bash
188188
func start
189189
```
190190
191-
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.
192192
193193
> [!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 function is 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)
198196
199197
[!INCLUDE [Cleanup](includes/signalr-quickstart-cleanup.md)]
200198
201199
Having issues? Try the [troubleshooting guide](signalr-howto-troubleshoot-guide.md) or [let us know](https://aka.ms/asrs/qspython).
202200
203201
## Next steps
204202
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.
207204
208205
> [!div class="nextstepaction"]
209206
> [SignalR Service bindings for Azure Functions](../azure-functions/functions-bindings-signalr-service.md)

0 commit comments

Comments
 (0)