简体   繁体   English

部署到 Azure 后 DocumentClient 不起作用

[英]DocumentClient not working after deploying to Azure

I am working on a POC (in .Net Core) to write some data to local Cosmos DB emulator using Azure DocumentClient.我正在开发一个 POC(在 .Net Core 中),以使用 Azure DocumentClient 将一些数据写入本地 Cosmos DB 模拟器。

private string _endpointUri = String.Empty;
private string _primaryKey = String.Empty;
private DocumentClient _client;
private string _databaseName = String.Empty;
private string _collectionName = String.Empty;

public CosmosDBStorage(IConfiguration configuration)
{
    _endpointUri = configuration["CosmosDBEndpointUri"];
    _primaryKey = configuration["CosmosDBPrimaryKey"];
    _client = new DocumentClient(new Uri(_endpointUri), _primaryKey);
    _databaseName = configuration["CosmosDBName"];
    _collectionName = configuration["CosmosDBCollectionName"];
}

public async Task WriteAsync(dynamic data)
{
    try
    {
        await this._client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName), data);
    }
    catch
    {
        throw;
    }
}

It works fine in my local, however, after deploying the app to Azure I am trying use the same local Cosmos DB emulator for testing.它在我的本地工作正常,但是,在将应用程序部署到 Azure 后,我尝试使用相同的本地 Cosmos DB 模拟器进行测试。 It fails with below error.它失败并出现以下错误。

Exception message: An error occurred while sending the request异常消息:发送请求时出错

Exception stack trace:异常堆栈跟踪:

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.DocumentClient.HttpRequestMessageHandler.<SendAsync>d__3.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.GatewayServiceConfigurationReader.<GetDatabaseAccountAsync>d__43.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Routing.GlobalEndpointManager.<GetDatabaseAccountFromAnyLocationsAsync>d__15.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.GatewayServiceConfigurationReader.<InitializeReaderAsync>d__45.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.DocumentClient.<InitializeGatewayConfigurationReader>d__319.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.DocumentClient.<GetInitializationTask>d__85.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.DocumentClient.<EnsureValidClientAsync>d__135.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.DocumentClient.<GetCollectionCacheAsync>d__70.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Documents.Client.DocumentClient.<CreateDocumentInlineAsync>d__143.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1T0
at BotFrameworkDev.Storage.CosmosDBStorage.<WriteAsync>d__7.MoveNext() in C:\GIS\ChatBot\BotFrameworkDev\BotFrameworkDev\Storage\CosmosDBStorage.cs:line 42
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at BotFrameworkDev.EchoBot.<OnTurn>d__8.MoveNext() in C:\GIS\ChatBot\BotFrameworkDev\BotFrameworkDev\EchoBot.cs:line 99

Any idea what could be the issue?知道可能是什么问题吗?

Update:更新:

Added inner exception details.添加了内部异常详细信息。

Exception message: A connection with the server could not be established异常消息:无法建立与服务器的连接

Exception stack trace:异常堆栈跟踪:

at BotFrameworkDev.Storage.CosmosDBStorage.<WriteAsync>d__7.MoveNext() in C:\GIS\ChatBot\BotFrameworkDev\BotFrameworkDev\Storage\CosmosDBStorage.cs:line 42
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at BotFrameworkDev.EchoBot.<OnTurn>d__8.MoveNext() in C:\GIS\ChatBot\BotFrameworkDev\BotFrameworkDev\EchoBot.cs:line 99

You cannot use the Local Emulator for testing in Azure.不能使用本地模拟器在 Azure 中进行测试。 Azure cannot find your localhost because it's outside of the boundaries of it's network. Azure 找不到你的localhost因为它超出了它的网络边界。

It will search in it's own network and fail.它将在自己的网络中搜索并失败。 You will need to point to an actual CosmosDB instance or somehow expose your emulator from a server or your pc to the Azure app service.你需要指向一个实际的 CosmosDB 实例,或者以某种方式将你的模拟器从服务器或你的电脑暴露给 Azure 应用服务。

Keep in mind that the CosmosDB Emulator is only supposed to be used for Local development and nothing else.请记住,CosmosDB 模拟器只应该用于本地开发而不是其他。 It is supposed to emulate behaviour and not be the real thing.它应该模仿行为,而不是真实的东西。

The recommended approach is to create a CosmosDB account and use that connection string.推荐的方法是创建一个 CosmosDB 帐户并使用该连接字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部署到Azure Web应用程序后Bootstrap下拉菜单不起作用 - Bootstrap dropdown not working after deploying to azure webapps .NET Core API 在 Azure 上部署后无法正常工作 - .NET Core API not working after deploying on Azure API 连接字符串在部署到 Azure 后不起作用 - API Connection String Not Working After Deploying to Azure Azure DocumentClient线程安全 - Azure DocumentClient thread safety 部署到Azure后OAuth无法正常工作[ASP.NET MVC] - OAuth not working after deploying to Azure [ASP.NET MVC] DocumentClient 返回 Azure-CosmosDB 中的单个对象 - DocumentClient return a Single Object in Azure-CosmosDB IdentityServer3 的 ASP.NET Identity 插件 UI (IdentityManager) 在部署到 Azure (WebApp) 后不起作用 - ASP.NET Identity plugin UI (IdentityManager) for IdentityServer3 not working after deploying to Azure (WebApp) 部署到Azure时无法进行代码优先迁移 - code first migration not working when deploying to Azure 有什么方法可以缓存Azure Cosmos DB的DocumentClient以获得更好的性能? - Any ways to cache DocumentClient of Azure Cosmos DB for better performance? Azure函数:绑定到DocumentClient与静态实例-建议什么? - Azure Functions: binding to DocumentClient versus static instance - what's recommended?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM