GET请求有效,而POST请求无效(Microsoft Azure美国中南部)

时间:2018-09-10 15:07:03

标签: azure post azure-functions

不确定发生了什么,但是对于Azure Functions的POST请求似乎不起作用。我已经用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;
            }
        } 
    }   
}

`

0 个答案:

没有答案