我在Azure中构建了一个简单的函数,它从json主体中获取文件的位置,并读取第一行以从所述文件中获取头文件。我正在Visual Studio中构建该函数,并使用打包的部署发布它。
我可以在Azure Functions下的门户上测试该函数,并有一个返回结果,但当我尝试并在Logic App中的函数时,我得到了404 Not Found Error。
我已经创建了MS给出的示例HTTPRequest函数,并且在相同的函数名下工作得很好,但是我不确定为什么我写的那个不能工作。
下面是我用于该函数的代码
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace Functions
{
public static class GetTableHeaders
{
[FunctionName("GetTableHeaders")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
IBinder binder,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string guid = req.Query["guid"];
string header = req.Query["header"];
string location = req.Query["location"];
string line = null;
string[] headers = null;
int size = 0;
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
guid = guid ?? data?.guid;
header = header ?? data?.header;
location = location ?? data?.location;
if (guid != null)
{
location = location.Substring(1);
using (var reader = binder.Bind<TextReader>(new BlobAttribute(
$"{location}", FileAccess.Read)))
{
line = reader.ReadLine();
headers = line.Split(',');
size = headers.Length;
if (!Convert.ToBoolean(header))
{
List<string> genericheaders = new List<string>();
for (int i = 1; i <= size; i++)
{
genericheaders.Add($"column{i}");
}
headers = genericheaders.ToArray();
}
};
return (ActionResult)new OkObjectResult($"{string.Join("|", headers)}");
}
else
{
return (ActionResult)new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}
}
}
下面是在MS示例函数中工作的代码:
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace Functions
{
public static class HttpFunction
{
[FunctionName("HttpFunction")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}
}
以下是在Azure Functions中运行代码的结果:
这里是我从逻辑应用程序得到的错误,一旦我尝试并使用该函数运行:
下面是逻辑应用程序json(将订阅ID替换为xxxx)
{
"$connections": {
"value": {
"azureblob": {
"connectionId": "/subscriptions/xxxx/resourceGroups/AMCDS/providers/Microsoft.Web/connections/azureblob",
"connectionName": "azureblob",
"id": "/subscriptions/xxxx/providers/Microsoft.Web/locations/westeurope/managedApis/azureblob"
},
"sql": {
"connectionId": "/subscriptions/xxxx/resourceGroups/AMCDS/providers/Microsoft.Web/connections/sql-1",
"connectionName": "sql-1",
"id": "/subscriptions/xxxx/providers/Microsoft.Web/locations/westeurope/managedApis/sql"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Create_GUID": {
"inputs": "@guid()",
"runAfter": {},
"type": "Compose"
},
"GetTableHeaders": {
"inputs": {
"body": {
"guid": "@{outputs('Create_GUID')}",
"header": "@{body('Insert_row_2')?['HasHeaders']}",
"location": "@{triggerBody()?['Path']}"
},
"function": {
"id": "/subscriptions/xxxx/resourceGroups/AMCDS/providers/Microsoft.Web/sites/AMCDSFunctionsWindows/functions/GetTableHeaders"
},
"method": "POST"
},
"runAfter": {
"Insert_row_2": [
"Succeeded"
]
},
"type": "Function"
},
"HttpFunction": {
"inputs": {
"body": {
"name": "Nirmal"
},
"function": {
"id": "/subscriptions/xxxx/resourceGroups/AMCDS/providers/Microsoft.Web/sites/AMCDSFunctionsWindows/functions/HttpFunction"
}
},
"runAfter": {
"Insert_row_2": [
"Succeeded"
]
},
"type": "Function"
},
"Insert_row_2": {
"inputs": {
"body": {
"DataType": "@{outputs('Split_FileName')[3]}",
"DateLoaded": "@{utcNow()}",
"FileDate": "@{outputs('Split_FileName')[1]}",
"FileName": "@triggerBody()?['Name']",
"FilePath": "@triggerBody()?['Path']",
"GUID": "@{outputs('Create_GUID')}",
"HasHeaders": "@if(equals(outputs('Split_FileName')[2],'#Y#'),true,false)"
},
"host": {
"connection": {
"name": "@parameters('$connections')['sql']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/tables/@{encodeURIComponent(encodeURIComponent('[meta].[FileMetadata]'))}/items"
},
"runAfter": {
"Split_FileName": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Split_FileName": {
"inputs": "@split(triggerBody()?['Name'],'.')",
"runAfter": {
"Create_GUID": [
"Succeeded"
]
},
"type": "Compose"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_blob_is_added_or_modified_(properties_only)": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/triggers/batch/onupdatedfile",
"queries": {
"folderId": "JTJmcmVjZWl2ZWQ=",
"maxFileCount": 10
}
},
"metadata": {
"JTJmcmVjZWl2ZWQ=": "/received"
},
"recurrence": {
"frequency": "Minute",
"interval": 1
},
"splitOn": "@triggerBody()",
"type": "ApiConnection"
}
}
}
}
3条答案
按热度按时间lymnna711#
你已经检查过了吗?
我也有同样的问题。它通过在逻辑应用JSON中使用“方法”参数来修复。
我的函数只接受“GET”方法,而逻辑应用JSON没有方法参数,所以我添加了"'method':'GET'”参数。
qqrboqgw2#
NotFound
错误发生在函数应用程序和逻辑应用程序位于不同位置并且logicapp触发器无法执行函数时。这种事在我身上发生过很多次。一个简单的解决方案是将这两种资源部署在同一位置,它应该可以工作。ddarikpa3#
再加上一个可能的解决方案。
在我的例子中,我重新提供了Function(Azure资源),但没有提供函数代码,那么对函数本身的引用仍然存在,但不是实际的
dlls
。所以,也试着测试函数本身。
是的,请确保您没有在功能的网络>访问限制部分或存储帐户(即代码所在的位置)中限制Azure逻辑应用程序。
希望这对某人有帮助。