问题描述
我想编写一个Web应用程序,允许用户编写C#脚本并使用Azure Functions执行它们.
I would like to write a web app that allows users to write C# scripts and execute them using Azure Functions.
我检查了Azure SDK文档,但没有找到用于管理Function App的任何nuget程序包.
I checked Azure SDK documentation and didn't find any nuget packages for managing Function Apps.
有没有办法:
- 获取可用的天蓝色函数列表
- 部署天蓝色函数
- 更新天蓝色函数
- 删除天蓝色函数
使用Azure SDK?如果没有,那将是另一种方式呢?
using Azure SDK? If not, what would be another way to do it?
2019年7月8日更新
我在Azure SDK(Microsoft.Azure.Management.WebSites)中找到了列表"和删除"功能:
I found List and Delete functions in Azure SDK (Microsoft.Azure.Management.WebSites):
列表:Msdn文档
删除Msdn文档
我测试了它们,它们起作用了.问题是与创建方法_CreateFunctionWithHttpMessagesAsync()
I tested them and they work.The problem is with Create method _CreateFunctionWithHttpMessagesAsync (Msdn Documentation)
尚不清楚应传递哪些参数才能使其正常工作.目前,我这样称呼它:
It is not clear which parameters should be passed for it to work.Currently I call it like this:
var response = await webClient.WebApps.CreateFunctionWithHttpMessagesAsync(ResourceGroupName, FunctionAppName, functionName, new FunctionEnvelope());
大约10到20秒,它会返回错误:"Microsoft.Azure.Management.WebSites.Models.DefaultErrorResponseException:操作返回了无效的状态码'InternalServerError'"
In about 10-20s it returns error:"Microsoft.Azure.Management.WebSites.Models.DefaultErrorResponseException : Operation returned an invalid status code 'InternalServerError'"
我认为这与空的FunctionEnvelope有关.我尝试传递各种值,但没有一个起作用.
I think it is related to empty FunctionEnvelope. I tried passing various values, but none of them worked.
推荐答案
AFAIK没有可用的SDK.但是有 REST API的
,可以让您执行上述所有操作.
AFAIK there is no SDK's available. But there are REST API's
which let you perform all the above operations.
对于更新和部署,您可以使用 zip部署
用于Azure Functions.
For updating and Deployment you can make use of the zip deployment
for Azure Functions.
使用指向您的 csproj
->
/p:DeployOnBuild=true /p:DeployTarget=Package;CreatePackageOnPublish=true
上面将生成一个zip文件,该文件可以在后面的部分中使用.
The above will generate a zip file which can be used in the later part.
现在第二步是使用此发布凭据rel ="nofollow noreferrer"> api ,如果收到响应,它将采用以下类格式
Now 2nd step is to obtain the Publish credentials
using this api, if you get the response it will in the below class format
public class GetPublishCredentials
{
public string Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Location { get; set; }
public Properties Properties { get; set; }
}
public class Properties
{
public string Name { get; set; }
public string PublishingUserName { get; set; }
public string PublishingPassword { get; set; }
public object PublishingPasswordHash { get; set; }
public object PublishingPasswordHashSalt { get; set; }
public object Metadata { get; set; }
public bool IsDeleted { get; set; }
public string ScmUri { get; set; }
}
获取凭据后,请按照以下代码来部署
或 update
您的Azure Functions
After obtaining the credentials, follow the below piece of code to deploy
or update
your Azure Functions
var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes
($"{functionCredentials.Properties.PublishingUserName}:{functionCredentials.Properties.PublishingPassword}"));
var stream = new MemoryStream(File.ReadAllBytes("zip file of azure function"));
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Auth);
var apiUrl = "https://" + parameters.FunctionAppName + ".scm.azurewebsites.net/api/zip/site/wwwroot";
var httpContent = new StreamContent(stream);
client.PutAsync(apiUrl, httpContent).Result;
}
现在应该部署您的functionapp.
Now your functionapp should be deployed.
这篇关于有没有一种使用Azure SDK管理Azure Function应用程序的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!