我正在开发一个poc(在.net内核中),使用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;
}
}
不过,在我的本地应用程序中运行良好,在将应用程序部署到azure之后,我正尝试使用同一个本地cosmos db模拟器进行测试。它失败了,错误如下。
异常消息:
发送请求时出错
异常堆栈跟踪:
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
你知道会有什么问题吗?
更新:
添加了内部异常详细信息。
异常消息:
无法建立与服务器的连接
异常堆栈跟踪:
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