我正在使用本地计算机上的Azure存储模拟器编写/调试Azure函数。不幸的是,我不确定应该使用哪个API或用于存储的正确URL。我的代码如下:
CosmosClient client = new CosmosClient(storageURL,authKeyString);
Database db = client.GetDatabase("devstoreaccount1");
container = db.getcontainer("leaderboard");
ItemResponse<StoredScore> resp = await container.CreateItemAsync<StoredScore>(newScore);
该函数的输入是:
storageURL = "http://127.0.0.1:10002"
authKeyString = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
在上面代码的最后一行,我得到一个异常:
DocDBTrace Warning: 0 : initializetask failed microsoft.Azure.Documents.DocumentClientException: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>InvalidHeaderValue</code>
<message xml:lang="en-US">The value for one of the HTTP headers is not in the correct format.
RequestId:ed82efd8-6cb8-4a2e-a793-16a38b3c8f2a
Time:2019-12-20T20:07:19.9539313Z</message>
</error>
Requesturi: http://127.0.0.1:10002/;
RequestMethod: GET;
Header: x-ms-version Length: 10;
Header: User-Agent Length: 98;
Header: x-ms-date Length: 29;
Header: Authorization Length: 84;,Request URI: /,RequestStats:,SDK: Windows/10.0.16299 cosmos-netstandard-sdk/3.4.2
at microsoft.Azure.Cosmos.GatewayStoreclient.ParseResponseAsync(HttpResponseMessage responseMessage,JsonSerializerSettings serializerSettings,DocumentServiceRequest request)
at microsoft.Azure.Cosmos.GatewayaccountReader.GetDatabaseaccountAsync(Uri serviceEndpoint)
at microsoft.Azure.Cosmos.Routing.GlobalEndpointManager.GetDatabaseaccountFromAnyLocationsAsync(Uri defaultEndpoint,IList`1 locations,Func`2 getDatabaseaccountFn)
at microsoft.Azure.Cosmos.GatewayaccountReader.InitializeReaderAsync()
at microsoft.Azure.Cosmos.CosmosaccountServiceConfiguration.InitializeAsync()
at microsoft.Azure.Cosmos.DocumentClient.InitializeGatewayConfigurationReaderAsync()
at microsoft.Azure.Cosmos.DocumentClient.GetInitializationTaskAsync(IStoreclientFactory storeclientFactory)
at microsoft.Azure.Cosmos.DocumentClient.EnsureValidClientAsync()
DocDBTrace Error: 0 : DocumentClientException with status code BadRequest,message: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>InvalidHeaderValue</code>
<message xml:lang="en-US">The value for one of the HTTP headers is not in the correct format.
RequestId:67e1f70a-c9c8-4aed-892c-964e8ff0f0e1
Time:2019-12-20T20:11:28.0006476Z</message>
</error>
Requesturi: http://127.0.0.1:10002/;
RequestMethod: GET;
Header: x-ms-version Length: 10;
Header: User-Agent Length: 98;
Header: x-ms-date Length: 29;
Header: Authorization Length: 82;,inner exception: null,and response headers: {
"Server": "microsoft-HTTPAPI/2.0","x-ms-request-id": "67e1f70a-c9c8-4aed-892c-964e8ff0f0e1","Date": "Fri,20 Dec 2019 20:11:27 GMT",}
DocDBTrace Information: 0 : Fail to reach global gateway http://127.0.0.1:10002/,microsoft.Azure.Documents.DocumentClientException: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>InvalidHeaderValue</code>
<message xml:lang="en-US">The value for one of the HTTP headers is not in the correct format.
RequestId:67e1f70a-c9c8-4aed-892c-964e8ff0f0e1
Time:2019-12-20T20:11:28.0006476Z</message>
</error>
Requesturi: http://127.0.0.1:10002/;
RequestMethod: GET;
Header: x-ms-version Length: 10;
Header: User-Agent Length: 98;
Header: x-ms-date Length: 29;
Header: Authorization Length: 82;,Func`2 getDatabaseaccountFn)
Exception thrown: 'microsoft.Azure.Documents.DocumentClientException' in System.Private.CoreLib.dll
Azure存储模拟器正在运行,我可以在Storage Explorer中对其进行操作。
有人可以帮助我弄清楚我做错了什么吗?我是否为此使用了“最佳” API?