我正在尝试 Azure Function Apps。
遵循 Open Weather map 教程中的示例的第一个在我使用 log.WriteLine()
后停止工作,它正确地引发了编译器错误。我更改为 log.Info()
,它一直提示 TraceWriter
不包含 WriteLine
的定义。
经过长时间的故障排除后,我创建了一个新函数,复制了损坏函数的所有内容,并且它立即起作用了。
像以前一样创建一个新函数,并开始对 Run()
方法进行更改,运行此函数会产生:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
请记住,函数 URL 基于创建函数时 Azure 生成的默认 key :https://.azurewebsites.net/api/WeatherWhereYouAre?code=my1really2RAndom3defauLT4Key5from6Azure==
创建了另一个函数,与默认的“Hello Azure”示例相比没有任何更改,它会产生 500 错误:
"Exception while executing function: Functions.HttpTriggerCSharp2 -> One or more errors occurred. -> Exception binding parameter 'req' -> Input string was not in a correct format."
这是project.json 文件的内容:
{
"frameworks": {
"net46": {
"dependencies": {
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.16.0",
"Microsoft.Azure.KeyVault": "2.3.2",
"Microsoft.AspNet.WebApi.Client": "5.2.3"
}
}
}
}
还有 run.csx:
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
name = name ?? data?.name;
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
编辑
在上图中,请注意这是 httpTriggerFSharp1,但异常(exception)的是 HttpTriggerCSharp2(这是唯一有效的!)
有什么方法可以正确解决这些问题吗?
最佳答案
对于 C# 的默认 HttpTrigger 模板,您可以按如下方式调用它:
Get https://brucefunapp.azurewebsites.net/api/HttpTriggerCSharp3?name=bruce&code=ItDhLMxwDYmTvMTYzVbbALtL5GEcmaL5DlzSaD4FRIuFdh17ZkY71g==
Or
Post https://brucefunapp.azurewebsites.net/api/HttpTriggerCSharp3?code=ItDhLMxwDYmTvMTYzVbbALtL5GEcmaL5DlzSaD4FRIuFdh17ZkY71g==
Content-type: application/json
{"name": "bruce"}
有关Azure Functions C#脚本的更多详细信息,您可以引用here .
Is there a way I can properly troubleshoot these?
根据我的理解,您可以利用Precompiled functions并使用Visual Studio 2017 Tools for Azure Functions用于创建、本地调试和发布到 Azure。
关于azure - 如何对 Flaky Azure 函数应用程序行为进行故障排除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46037959/