Не уверен, что происходит, но похоже, что POST-запросы для функций Azure не работают. Я проверил это с помощью Postman и получаю нулевой ответ от POST-запроса к моей функции, но я получаю ответ по умолчанию при отправке GET-запроса.
Мои ресурсы также расположены в дата-центре на юге центральной части США ... Я полагаю, что это способствует ... но просто чтобы убедиться, что я хотел бы знать, если кто-то еще получает эту ошибку? Может ли быть что-то, что я делаю неправильно, чтобы GET работал, а не POST?
РЕДАКТИРОВАТЬ: возвращается код 500 внутренняя ошибка сервера. Вот стек вызовов от Application Insights:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__17.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 293)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<TryExecuteAsync>d__14.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 89)
Inner exception System.InvalidOperationException handled at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw:
at Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\DelayedException.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 27)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithWatchersAsync>d__24.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 478)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__23.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 444)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor+<ExecuteWithLoggingAsync>d__17.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 249)
Inner exception Newtonsoft.Json.JsonSerializationException handled at Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw:
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject (Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Newtonsoft.Json.Linq.JToken.ToObject (Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Newtonsoft.Json.Linq.JToken.ToObject (Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider+HttpTriggerBinding.ConvertValueIfNecessary (Microsoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Http\HttpTriggerAttributeBindingProvider.csMicrosoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 406)
at Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider+HttpTriggerBinding.ApplyBindingData (Microsoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Http\HttpTriggerAttributeBindingProvider.csMicrosoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 228)
at Microsoft.Azure.WebJobs.Extensions.Http.HttpTriggerAttributeBindingProvider+HttpTriggerBinding+<BindAsync>d__10.MoveNext (Microsoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions.Http\HttpTriggerAttributeBindingProvider.csMicrosoft.Azure.WebJobs.Extensions.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 174)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding1+<BindCoreAsync>d__8.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=nullMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\TriggeredFunctionBinding.csMicrosoft.Azure.WebJobs.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null: 57)
А вот код функции:
using Alexa.NET.Request;
using Alexa.NET.Response;
using Alexa.NET.Request.Type;
using System.Data.SqlClient;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs.Host;
using System.Data;
using Alexa.NET;
using System;
namespace MyFunction
{
public static class MyFunction
{
static readonly string azureConnection = "---Connection String---";
static SqlConnection connection;
static string welcomeMessage = "Welcome.";
[FunctionName("FuncCall")]
public static SkillResponse Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)][FromBody]SkillRequest incomingRequest, TraceWriter log)
{
SkillResponse skillResponseForBuilder;
PlainTextOutputSpeech outputSpeech = new PlainTextOutputSpeech();
switch (incomingRequest.Request)
{
case LaunchRequest launch:
outputSpeech.Text = welcomeMessage;
SkillResponse skillResponse = new SkillResponse();
skillResponse.Version = "1.0";
skillResponse.SessionAttributes = null;
skillResponse.Response = new ResponseBody();
skillResponse.Response.OutputSpeech = outputSpeech;
skillResponse.Response.ShouldEndSession = false;
return skillResponse;
case IntentRequest intent:
string intentName = intent.Intent.Name;
if (intentName.Equals("RollTheDice"))
{
return RollDiceHandler(incomingRequest);
}
else if (intentName.Equals("CheckIn"))
{
return CheckInHandler(incomingRequest);
}
else
{
DataTable funcdt = new DataTable();
using (connection = new SqlConnection(azureConnection))
using (
SqlCommand cmd = new SqlCommand("SPCallFunction", connection)
{
CommandType = CommandType.StoredProcedure
})
{
connection.Open();
cmd.Parameters.Add(new SqlParameter("@IntentKey", intentName));
SqlDataReader funcdr = cmd.ExecuteReader();
funcdt.Load(funcdr);
if (funcdt.Rows.Count != 0)
{
outputSpeech.Text = funcdt.Rows[0]["IntentValue"].ToString();
connection.Close();
}
else
{
outputSpeech.Text = incomingRequest.GetRequestType().ToString();
connection.Close();
}
}
}
skillResponseForBuilder = ResponseBuilder.Tell(outputSpeech);
return skillResponseForBuilder;
default:
outputSpeech.Text = "Error.";
skillResponseForBuilder = ResponseBuilder.Tell(outputSpeech.Text);
return skillResponseForBuilder;
}
}
// Test dialog handler
public static SkillResponse RollDiceHandler(SkillRequest req)
{
SkillResponse skillResponse = new SkillResponse();
PlainTextOutputSpeech outputSpeech = new PlainTextOutputSpeech();
var request = req.Request as IntentRequest;
if (request.DialogState == DialogState.Started)
{
return ResponseBuilder.DialogDelegate(req.Session, request.Intent);
}
else if (request.DialogState != DialogState.Completed)
{
return ResponseBuilder.DialogDelegate(req.Session);
}
else
{
skillResponse.Response = new ResponseBody();
skillResponse.Response.ShouldEndSession = false;
if (request.Intent.Slots["DiceType"].Value != null)
{
var numSides = request.Intent.Slots["DiceType"].Value;
var rollResults = new Random().Next(Math.Max(1, Convert.ToInt32(numSides) - 1)) + 1;
outputSpeech.Text = "I rolled a " + numSides + " sided die and got a " + rollResults;
skillResponse.Response.OutputSpeech = outputSpeech;
skillResponse.Response.ShouldEndSession = true;
skillResponse.Version = "1.0";
}
else
{
outputSpeech.Text = "Hello.";
skillResponse.Response.OutputSpeech = outputSpeech;
skillResponse.Version = "1.0";
if (request.Intent.Slots["DiceType"].Value != null)
{
var numSides = request.Intent.Slots["DiceType"].Value;
var rollResults = new Random().Next(Math.Max(1, Convert.ToInt32(numSides) - 1)) + 1;
outputSpeech.Text = "I rolled a " + numSides + " sided die and got a " + rollResults;
skillResponse.Response.OutputSpeech = outputSpeech;
skillResponse.Response.ShouldEndSession = true;
skillResponse.Version = "1.0";
}
}
return skillResponse;
}
}
public static SkillResponse CheckInHandler(SkillRequest req)
{
SkillResponse skillResponse = new SkillResponse();
PlainTextOutputSpeech outputSpeech = new PlainTextOutputSpeech();
var request = req.Request as IntentRequest;
if (request.DialogState == DialogState.Started)
{
return ResponseBuilder.DialogDelegate(req.Session, request.Intent);
}
else if (request.DialogState != DialogState.Completed)
{
return ResponseBuilder.DialogDelegate(req.Session);
}
else
{
skillResponse.Response = new ResponseBody();
skillResponse.Response.ShouldEndSession = false;
if (request.Intent.Slots["TechnicianName"].Value != null && request.Intent.Slots["TicketNumber"].Value != null)
{
var techName = request.Intent.Slots["TechnicianName"].Value;
var ticketNumber = request.Intent.Slots["TicketNumber"].Value;
if (request.Intent.Slots["TechnicianCompany"].Value != null)
{
var techCompany = request.Intent.Slots["TechnicianCompany"].Value;
}
outputSpeech.Text = "Thank you.";
skillResponse.Response.OutputSpeech = outputSpeech;
skillResponse.Response.ShouldEndSession = true;
skillResponse.Version = "1.0";
}
return skillResponse;
}
}
}
}
`