Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure函数,输出到cosmos db_C#_Azure_Azure Functions_Azure Cosmosdb - Fatal编程技术网

C# Azure函数,输出到cosmos db

C# Azure函数,输出到cosmos db,c#,azure,azure-functions,azure-cosmosdb,C#,Azure,Azure Functions,Azure Cosmosdb,我正在尝试创建一个函数,它将接受一些输入并将其存储在cosmos db中。我编写了这个函数: using Microsoft.AspNetCore.Http; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.Azure.WebJobs.Host; [FunctionName("DocumentUpdates")] public st

我正在尝试创建一个函数,它将接受一些输入并将其存储在cosmos db中。我编写了这个函数:

using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

    [FunctionName("DocumentUpdates")]
        public static void Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req,
            [CosmosDB("Fagkveld", "ViktigeData", CreateIfNotExists = true, Id = "Id", ConnectionStringSetting = "CosmosDbConn")]out dynamic document,
            TraceWriter log)
        {
            document = new {Id="Identifier1", Title = "Some Title"};
}
但当我运行此命令时,会出现以下错误:

[24.04.2018 07:05:15] Executed 'DocumentUpdates' (Failed, Id=ce0deab0-5ba3-4bb0-9399-96661c52ecb8)
[24.04.2018 07:05:15] System.Private.CoreLib: Exception while executing function: DocumentUpdates. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'document'. Microsoft.Azure.DocumentDB.Core: Value cannot be null.
[24.04.2018 07:05:15] Parameter name: serviceEndpoint.

有人能告诉我我做错了什么吗?我找不到任何serviceEndpoint参数?

请参阅以下代码:

using System.Net.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;

namespace JayGongCosmosDB
{
    public static class Function2
    {
        [FunctionName("Function1")]
        public static void Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req,
             [DocumentDB("db", "coll", Id = "id", ConnectionStringSetting = "myCosmosDB")] out dynamic document)
        {
            document = new { Id = "Identifier1", Title = "Some Title" };
        }
    }
}
基于,您需要使用
DocumentDB
而不是
CosmosDB
(不应通过编译)


希望它能帮助您。

请参考以下代码:

using System.Net.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;

namespace JayGongCosmosDB
{
    public static class Function2
    {
        [FunctionName("Function1")]
        public static void Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req,
             [DocumentDB("db", "coll", Id = "id", ConnectionStringSetting = "myCosmosDB")] out dynamic document)
        {
            document = new { Id = "Identifier1", Title = "Some Title" };
        }
    }
}
基于,您需要使用
DocumentDB
而不是
CosmosDB
(不应通过编译)


希望它能帮助您。

尝试从属性中删除
Id
参数。指定
Id
时,函数将尝试查询该文档。在您的情况下,您不希望这样做,因为您正在尝试执行输出绑定


[CosmosDB(“Fagkveld”、“ViktigeData”,CreateIfNotExists=true,connectionString=“CosmosDbConn”)]输出动态文档
尝试从属性中删除
Id
参数。指定
Id
时,函数将尝试查询该文档。在您的情况下,您不希望这样做,因为您正在尝试执行输出绑定


[CosmosDB(“Fagkveld”,“ViktigeData”,CreateIfNotExists=true,connectionString=“CosmosDbConn”)]输出动态文档

我不确定最终是什么解决了这个问题。但我按照@Vladislav的建议做了,并清洗了溶液。我还重新安装了所有软件包,并重新检查了所有连接字符串。出于某种原因,它现在起作用了。
谢谢你的建议

我不确定到底是什么解决了这个问题。但我按照@Vladislav的建议做了,并清洗了溶液。我还重新安装了所有软件包,并重新检查了所有连接字符串。出于某种原因,它现在起作用了。
谢谢你的建议

根据下面的文档,您应该使用
DocumentDB
输出绑定类型,而不是
CosmosDB
。你试过了吗?您可以使用CosmosDBTrigger,它是Microsoft.Azure.WebJobs的一部分,但您没有CreateIfNotExists和Id标志。如果可以使用DocumentDB,则可以使用这两个标志。@Vladislav我使用的是函数版本2,其他绑定也在其中重命名。所以我想我应该使用CosmosDB属性。也找不到DocumentDb属性。@HoriaToma cosmosDb触发器用于检测cosmosDb中的更改,对吗?我正在尝试使用http触发函数的InputValue更新cosmos db。@Zaphod我正在使用运行时1.x,但我仍然定期遇到类似问题。最常见的情况是,它们出现在我添加/更新一些nuget包之后。在这种情况下,我尝试将包还原为旧版本,并测试每个版本的绑定是否成功。另一种情况(目前与之一致)是函数项目需要“清理”,然后立即“启动调试”。每次我想调试它的时候,在我看来,这又和一些nuget有关。。。希望这能帮助您……根据下面的文档,您应该使用
DocumentDB
输出绑定类型,而不是
CosmosDB
。你试过了吗?您可以使用CosmosDBTrigger,它是Microsoft.Azure.WebJobs的一部分,但您没有CreateIfNotExists和Id标志。如果可以使用DocumentDB,则可以使用这两个标志。@Vladislav我使用的是函数版本2,其他绑定也在其中重命名。所以我想我应该使用CosmosDB属性。也找不到DocumentDb属性。@HoriaToma cosmosDb触发器用于检测cosmosDb中的更改,对吗?我正在尝试使用http触发函数的InputValue更新cosmos db。@Zaphod我正在使用运行时1.x,但我仍然定期遇到类似问题。最常见的情况是,它们出现在我添加/更新一些nuget包之后。在这种情况下,我尝试将包还原为旧版本,并测试每个版本的绑定是否成功。另一种情况(目前与之一致)是函数项目需要“清理”,然后立即“启动调试”。每次我想调试它的时候,在我看来,这又和一些nuget有关。。。希望这对您有所帮助…我使用的是Azure函数版本2.x,因此该属性被重命名为CosmosDb。。本页顶部的“注意事项”:我使用的是Azure函数版本2.x,因此该属性被重命名为CosmosDb。。本页顶部的“注意事项”:你在VS中看到了吗?在不共享任何秘密的情况下,local.settings.json文件中的“CosmosDbConn”值是多少?它是否使用完整的Cosmos连接字符串(带有AccountEndpoint和AccountKey)?您是否在VS中看到了这一点?在不共享任何秘密的情况下,local.settings.json文件中的“CosmosDbConn”值是多少?它是否使用完整的Cosmos连接字符串(带有AccountEndpoint和AccountKey)?