我是Azure函數的新手。 我想寫一個Http觸發器,它不僅會「失敗」壞JSON(與我的架構不匹配,我想通過與他們提交的JSON有關的無效消息向調用者提供反饋)如何將HttpTrigger連接到設計器
好了,第一我長大VS2017。
然後我編碼它。我可以用郵遞員來測試它,它郵遞員在測試過程中正常工作。
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
////using MyExceptionLibrary;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
namespace MyNamespace.AzureFunctionsOne
{
public static class MyFirstHttpTrigger
{
[FunctionName("MyFirstHttpTriggerFunctionName")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function MyFirstHttpTriggerFunctionName about to process a request.");
try
{
string jsonSchemaText = @"{
'description': 'A person',
'type': 'object',
'properties':
{
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}";
JSchema schema = JSchema.Parse(jsonSchemaText);
var content = req.Content;
string jsonContent = content.ReadAsStringAsync().Result;
JObject jobj = JObject.Parse(jsonContent);
IList<string> messages;
bool valid = jobj.IsValid(schema, out messages);
if (!valid)
{
string errorMsg = string.Join(",", messages);
throw new ArgumentOutOfRangeException(string.Format("Bad Json. ({0})", errorMsg));
}
}
catch (Exception ex)
{
string errorMsg = ex.Message; //// ExceptionHelper.GenerateFullFlatMessage(ex);
log.Error(errorMsg);
return req.CreateResponse(HttpStatusCode.BadRequest, errorMsg);
}
log.Info("C# HTTP trigger function MyFirstHttpTriggerFunctionName processed a request.");
return req.CreateResponse(HttpStatusCode.OK);
}
}
}
然後我「發佈「這種天藍色的功能n到雲端。
我的問題是現在........我該如何連接到邏輯應用程序設計器是觸發器?
在下面,我可以添加通用請求觸發器。
在下文中,我也找過我〜〜蔚藍的HTTP觸發器,我公佈,沒有運氣。
所以我無法弄清楚如何讓我的自定義HTTP觸發器可用的邏輯應用程序設計,因此它可以是入口點觸發。
我是否缺少一些基本概念?
我的最後一步就是:
我想要一個第三方來發布一些JSON到我的Azure的邏輯應用作爲HTTP請求。這應該是觸發器。但是我只想讓觸發器在提交有效的json時繼續運行。 (我知道這可以通過通用請求觸發器來完成)。我的警告(也就是我自定義的http觸發器)是我希望第三方獲取模式違規消息,以便他們知道他們做錯了什麼。
對於未來的讀者。我的問題有點「關閉」,因爲我最初並不瞭解Azure函數存在於Logic-Apps之外的世界中。我能夠得到我想要的,但不是通過創建自定義的邏輯應用程序「觸發器」。我在這裏記錄它。 https://granadacoder.wordpress.com/2017/08/21/actionconditionfailed-the-execution-of-template-action-condition-is-skipped-expected-status-values-succeeded-and-actual-value-failed- azure-logic-apps/ – granadaCoder