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
title: Create your first durable function in Azure using C#
3
-
description: Create and publish an Azure Durable Function using Visual Studio.
3
+
description: Create and publish an Azure Durable Function using Visual Studio or Visual Studio Code.
4
4
author: jeffhollan
5
5
6
6
ms.topic: quickstart
7
-
ms.date: 11/02/2019
7
+
ms.date: 03/18/2020
8
8
ms.author: azfuncdf
9
+
zone_pivot_groups: code-editors-set-one
9
10
10
11
---
12
+
11
13
# Create your first durable function in C\#
12
14
13
15
*Durable Functions* is an extension of [Azure Functions](../functions-overview.md) that lets you write stateful functions in a serverless environment. The extension manages state, checkpoints, and restarts for you.
In this article, you learn how to use Visual Studio Code to locally create and test a "hello world" durable function. This function orchestrates and chains-together calls to other functions. You then publish the function code to Azure. These tools are available as part of the VS Code [Azure Functions extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions).
20
+
21
+

22
+
23
+
## Prerequisites
24
+
25
+
To complete this tutorial:
26
+
27
+
* Install [Visual Studio Code](https://code.visualstudio.com/download).
## <aname="create-an-azure-functions-project"></a>Create your local project
42
+
43
+
In this section, you use Visual Studio Code to create a local Azure Functions project.
44
+
45
+
1. In Visual Studio Code, press F1 (or Ctrl/Cmd+Shift+P) to open the command palette. In the command palette, search for and select `Azure Functions: Create New Project...`.
46
+
47
+

48
+
49
+
1. Choose an empty folder location for your project and choose **Select**.
50
+
51
+
1. Following the prompts, provide the following information:
52
+
53
+
| Prompt | Value | Description |
54
+
| ------ | ----- | ----------- |
55
+
| Select a language for your function app project | C# | Create a local C# Functions project. |
56
+
| Select a version | Azure Functions v3 | You only see this option when the Core Tools aren't already installed. In this case, Core Tools are installed the first time you run the app. |
57
+
| Select a template for your project's first function | Skip for now ||
58
+
| Select how you would like to open your project | Open in current window | Reopens VS Code in the folder you selected. |
59
+
60
+
Visual Studio Code installs the Azure Functions Core Tools, if needed. It also creates a function app project in a folder. This project contains the [host.json](../functions-host-json.md) and [local.settings.json](../functions-run-local.md#local-settings-file) configuration files.
61
+
62
+
## Add functions to the app
63
+
64
+
The following steps use a template to create the durable function code in your project.
65
+
66
+
1. In the command palette, search for and select `Azure Functions: Create Function...`.
67
+
68
+
1. Following the prompts, provide the following information:
69
+
70
+
| Prompt | Value | Description |
71
+
| ------ | ----- | ----------- |
72
+
| Select a template for your function | DurableFunctionsOrchestration | Create a Durable Functions orchestration |
73
+
| Provide a function name | HelloOrchestration | Name of the class in which functions are created |
74
+
| Provide a namespace | Company.Function | Namespace for the generated class |
75
+
76
+
1. When VS Code prompts you to select a storage account, choose **Select storage account**. Following the prompts, provide the following information to create a new storage account in Azure.
77
+
78
+
| Prompt | Value | Description |
79
+
| ------ | ----- | ----------- |
80
+
| Select subscription |*name of your subscription*| Select your Azure subscription |
81
+
| Select a storage account | Create a new storage account ||
82
+
| Enter the name of the new storage account |*unique name*| Name of the storage account to create |
83
+
| Select a resource group |*unique name*| Name of the resource group to create |
84
+
| Select a location |*region*| Select a region close to you |
85
+
86
+
A class containing the new functions is added to the project. VS Code also adds the storage account connection string to *local.settings.json* and a reference to the [`Microsoft.Azure.WebJobs.Extensions.DurableTask`](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.DurableTask) NuGet package to the *.csproj* project file.
87
+
88
+
Open the new *HelloOrchestration.cs* file to view the contents. This durable function is a simple function chaining example with the following methods:
89
+
90
+
| Method | FunctionName | Description |
91
+
| ----- | ------------ | ----------- |
92
+
|**`RunOrchestrator`**|`HelloOrchestration`| Manages the durable orchestration. In this case, the orchestration starts, creates a list, and adds the result of three functions calls to the list. When the three function calls are complete, it returns the list. |
93
+
|**`SayHello`**|`HelloOrchestration_Hello`| The function returns a hello. It is the function that contains the business logic that is being orchestrated. |
94
+
|**`HttpStart`**|`HelloOrchestration_HttpStart`| An [HTTP-triggered function](../functions-bindings-http-webhook.md) that starts an instance of the orchestration and returns a check status response. |
95
+
96
+
Now that you've created your function project and a durable function, you can test it on your local computer.
97
+
98
+
## Test the function locally
99
+
100
+
Azure Functions Core Tools lets you run an Azure Functions project on your local development computer. You're prompted to install these tools the first time you start a function from Visual Studio Code.
101
+
102
+
1. To test your function, set a breakpoint in the `SayHello` activity function code and press F5 to start the function app project. Output from Core Tools is displayed in the **Terminal** panel.
103
+
104
+
> [!NOTE]
105
+
> Refer to the [Durable Functions Diagnostics](durable-functions-diagnostics.md#debugging) for more information on debugging.
106
+
107
+
1. In the **Terminal** panel, copy the URL endpoint of your HTTP-triggered function.
108
+
109
+

110
+
111
+
1. Using a tool like [Postman](https://www.getpostman.com/) or [cURL](https://curl.haxx.se/), send an HTTP POST request to the URL endpoint.
112
+
113
+
The response is the initial result from the HTTP function letting us know the durable orchestration has started successfully. It is not yet the end result of the orchestration. The response includes a few useful URLs. For now, let's query the status of the orchestration.
114
+
115
+
1. Copy the URL value for `statusQueryGetUri` and paste it in the browser's address bar and execute the request. Alternatively you can also continue to use Postman to issue the GET request.
116
+
117
+
The request will query the orchestration instance for the status. You should get an eventual response, which shows us the instance has completed, and includes the outputs or results of the durable function. It looks like:
118
+
119
+
```json
120
+
{
121
+
"name": "HelloOrchestration",
122
+
"instanceId": "9a528a9e926f4b46b7d3deaa134b7e8a",
123
+
"runtimeStatus": "Completed",
124
+
"input": null,
125
+
"customStatus": null,
126
+
"output": [
127
+
"Hello Tokyo!",
128
+
"Hello Seattle!",
129
+
"Hello London!"
130
+
],
131
+
"createdTime": "2020-03-18T21:54:49Z",
132
+
"lastUpdatedTime": "2020-03-18T21:54:54Z"
133
+
}
134
+
```
135
+
136
+
1. To stop debugging, press **Shift + F5** in VS Code.
137
+
138
+
After you've verified that the function runs correctly on your local computer, it's time to publish the project to Azure.
In this article, you learn how to use the Visual Studio 2019 to locally create and test a "hello world" durable function. This function orchestrates and chains-together calls to other functions. You then publish the function code to Azure. These tools are available as part of the Azure development workload in Visual Studio 2019.
150
+
1. Paste this new URL for the HTTP request into your browser's address bar. You should get the same status response as before when using the published app.
151
+
152
+
## Next steps
153
+
154
+
You have used Visual Studio Code to create and publish a C# durable function app.
155
+
156
+
> [!div class="nextstepaction"]
157
+
> [Learn about common durable function patterns](durable-functions-overview.md#application-patterns)
158
+
159
+
::: zone-end
160
+
161
+
::: zone pivot="code-editor-visualstudio"
162
+
163
+
In this article, you learn how to Visual Studio 2019 to locally create and test a "hello world" durable function. This function orchestrates and chains-together calls to other functions. You then publish the function code to Azure. These tools are available as part of the Azure development workload in Visual Studio 2019.
18
164
19
165

20
166
@@ -34,7 +180,7 @@ The Azure Functions template creates a project that can be published to a functi
34
180
35
181
1. In Visual Studio, select **New** > **Project** from the **File** menu.
36
182
37
-
1. In the **Add a new project** dialog, search for `functions`, choose the **Azure Functions** template, and select **Next**.
183
+
1. In the **Create a new project** dialog, search for `functions`, choose the **Azure Functions** template, and select **Next**.
38
184
39
185

40
186
@@ -46,7 +192,7 @@ The Azure Functions template creates a project that can be published to a functi
|**Version**| Azure Functions 2.0 <br />(.NET Core) | Creates a function project that uses the version 2.0 runtime of Azure Functions, which supports .NET Core. Azure Functions 1.0 supports the .NET Framework. For more information, see [How to target Azure Functions runtime version](../functions-versions.md). |
195
+
| **Version** | Azure Functions 3.0 <br />(.NET Core) | Creates a function project that uses the version 3.0 runtime of Azure Functions, which supports .NET Core 3.1. For more information, see [How to target Azure Functions runtime version](../functions-versions.md). |
50
196
| **Template** | Empty | Creates an empty function app. |
51
197
| **Storage account** | Storage Emulator | A storage account is required for durable function state management. |
52
198
@@ -58,16 +204,13 @@ The following steps use a template to create the durable function code in your p
58
204
59
205
1. Right-click the project in Visual Studio and select **Add** > **New Azure Function**.
60
206
61
-

207
+

62
208
63
209
1. Verify **Azure Function** is selected from the add menu, type a name for your C# file, and then select **Add**.
64
210
65
211
1. Select the **Durable Functions Orchestration** template and then select **Ok**
> This template currently creates a durable function using an older 1.x version of the extension. See the [Durable Functions Versions](durable-functions-versions.md) article for information about how to upgrade to the newer 2.x versions of Durable Functions.
A new durable function is added to the app. Open the new .cs file to view the contents. This durable function is a simple function chaining example with the following methods:
73
216
@@ -131,7 +274,7 @@ You must have a function app in your Azure subscription before you can publish y
131
274
132
275
The URL that calls your durable function HTTP trigger should be in the following format:
2. Paste this new URL for the HTTP request into your browser's address bar. You should get the same status response as before when using the published app.
137
280
@@ -140,4 +283,6 @@ You must have a function app in your Azure subscription before you can publish y
140
283
You have used Visual Studio to create and publish a C# durable function app.
141
284
142
285
> [!div class="nextstepaction"]
143
-
> [Learn about common durable function patterns](durable-functions-overview.md#application-patterns)
286
+
> [Learn about common durable function patterns](durable-functions-overview.md#application-patterns)
0 commit comments