我正在嘗試將我的 Azure HTTP 函數(shù)從 Visual Studio Code 發(fā)布到我們的 Azure 平臺。該代碼在本地運行該函數(shù)時工作正常并成功發(fā)布,但在發(fā)布時拋出以下錯誤。我嘗試使用 DocumentDB 而不是 CosmosDB,但缺乏將數(shù)據(jù)插入 CosmosDB 所需的插入功能。 Stackoverflow 沒有針對此類特定問題的解決方案。功能碼//write to cosmosdb[FunctionName("InsertItem")] public static HttpResponseMessage Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]HttpRequestMessage req, [CosmosDB( databaseName: "ToDoList", collectionName: "RFIDContainer", ConnectionStringSetting = "myCosmosDBConnection")] out RFIDBaseTag document, ILogger log) { string hexData = ""; string afi = ""; string eid = ""; string dsfid = ""; //Guid DeviceID = new Guid(); //Guid AppID = new Guid(); var content = req.Content; string jsonContent = content.ReadAsStringAsync().Result; dynamic json = JsonConvert.DeserializeObject<MyClass>(jsonContent); hexData = json?.hexData; afi = json?.afi; eid = json?.eid; dsfid = json?.dsfid; /*Guid devGuid; Guid.TryParse(json.AppID.ToString(), out devGuid); DeviceID = devGuid; Guid appGuid; Guid.TryParse(json.AppID.ToString(), out appGuid); AppID = appGuid;*/ byte[] hexToByte = AzureRFIDTagReader.StringToByteArray(hexData); RawRFIDReading raw = new RawRFIDReading(); raw.afi = afi; raw.eid = eid; raw.dsfid = dsfid; raw.RawData = hexToByte; RFIDBaseTag rtag = RFIDTagFactory.GetTag(raw); string serializedtag = JsonConvert.SerializeObject(rtag); //document = JsonConvert.DeserializeObject<MyClass>(jsonContent); //document = JsonConvert.DeserializeObject<RFIDBaseTag(serializedtag); document = rtag; log.LogInformation($"C# Queue trigger function inserted one row"); return new HttpResponseMessage(HttpStatusCode.Created); }錯誤信息:函數(shù)(xxx/InsertItem)錯誤:Microsoft.Azure.WebJobs.Host:索引方法“InsertItem”錯誤。 Microsoft.Azure.WebJobs.Host:無法解析屬性“CosmosDBAttribute.ConnectionStringSetting”的值。確保該設(shè)置存在并且具有有效值。我可以在本地發(fā)布該函數(shù),但不能在 Azure 上發(fā)布。有什么建議么?
1 回答

米琪卡哇伊
TA貢獻1998條經(jīng)驗 獲得超6個贊
當您發(fā)布函數(shù)時,您的local.settings.json
文件不會發(fā)布。
您需要將這些設(shè)置添加為 Azure Functions 應(yīng)用程序設(shè)置的一部分。在您的情況下,您需要在其中添加 myCosmosDBConnection
值。
- 1 回答
- 0 關(guān)注
- 122 瀏覽
添加回答
舉報
0/150
提交
取消