- Azure Serverless Computing Cookbook
- Praveen Kumar Sreeram
- 362字
- 2021-07-02 20:23:01
How to do it...
- Navigate to the Integrate tab of the RegisterUser HTTP trigger function.
- Click on the New Output button and select Azure Table Storage then click on the Select button:

- Once you click on the Select button in the previous step, you will be prompted to choose the following settings of the Azure Table storage output bindings:
- Table parameter name: This is the name of the parameter that you will be using in the Run method of the Azure Function. For this example, please provide objUserProfileTable as the value.
- Table name: A new table in the Azure Table storage will be created to persist the data. If the table doesn't exist already, Azure will automatically create one for you! For this example, please provide tblUserProfile as the table name.
- Storage account connection: If you don't see the Storage account connection string, click on the new (shown in the following screenshot) to create a new one or to choose an existing storage account.
- The Azure Table storage output bindings should be as shown in the following screenshot:

- Click on Save to save the changes.
- Navigate to the code editor by clicking on the function name and paste the following code:
#r "Microsoft.WindowsAzure.Storage"
using System.Net;
using Microsoft.WindowsAzure.Storage.Table;
public static async Task<HttpResponseMessage>
Run(HttpRequestMessage req,TraceWriter
log,CloudTable objUserProfileTable)
{
dynamic data = await
req.Content.ReadAsAsync<object>();
string firstname= data.firstname;
string lastname=data.lastname;
UserProfile objUserProfile = new UserProfile(firstname,
lastname);
TableOperation objTblOperationInsert =
TableOperation.Insert(objUserProfile);
objUserProfileTable.Execute(objTblOperationInsert);
return req.CreateResponse(HttpStatusCode.OK,
"Thank you for Registering..");
}
public class UserProfile : TableEntity
{
public UserProfile(string lastName, string firstName)
{
this.PartitionKey = "p1";
this.RowKey = Guid.NewGuid().ToString();;
this.FirstName = firstName;
this.LastName = lastName;
}
public UserProfile() { }
public string FirstName { get; set; }
public string LastName { get; set; }
}
- Let's execute the function by clicking on the Run button of the Test tab by passing firstname and lastname parameters in the Request body as shown in the following screenshot:

- If everything went well, you should get a Status 200 OK message in the Output box as shown in the preceding screenshot. Let's navigate to Azure Storage Explorer and view the table storage to see if the table named tblUserProfile was created successfully:

推薦閱讀
- Rust編程:入門、實戰(zhàn)與進階
- 算法大爆炸:面試通關步步為營
- 64位匯編語言的編程藝術
- Mastering Ubuntu Server
- 組態(tài)軟件技術與應用
- Azure Serverless Computing Cookbook
- Laravel Application Development Blueprints
- 數據結構:Python語言描述
- 從零開始學Unity游戲開發(fā):場景+角色+腳本+交互+體驗+效果+發(fā)布
- C語言程序設計
- Java Web應用開發(fā)
- Spring Boot 2+Thymeleaf企業(yè)應用實戰(zhàn)
- SOA Patterns with BizTalk Server 2013 and Microsoft Azure(Second Edition)
- Visual C++ 開發(fā)從入門到精通
- Go語言編程之旅:一起用Go做項目