通过.NET确定每个查询的DocumentDB请求费用 [英] Determining DocumentDB Request Charge per query via .NET

查看:72
本文介绍了通过.NET确定每个查询的DocumentDB请求费用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过提供的.NET客户端库执行DocumentDB查询请求时是否有可能获得请求费".详细信息返回到基本的HTTP标头"x-ms-request-charge"中,我可以通过Fiddler等进行监视,但是如果我可以直接通过.NET获取它,则更喜欢.

I'm trying to figure out if it's possible to get the "request charge" when performing DocumentDB query requests via the supplied .NET client library. The details come back in the underlying HTTP header "x-ms-request-charge" which I can monitor via Fiddler etc but would prefer if I could get it directly via .NET.

有人这样做吗?或者至少能够确认这根本不可能吗?

Has anyone done this? Or at least able to confirm if it's simply not possible?

更新:

增加了说明,我在执行查询而不是其他操作时要收取请求费用.

Added clarification that I'm after request charge when performing queries and not other operations.

推荐答案

您应该可以通过.Net库获得它.例如,请看下面的屏幕截图,其中显示了Create New User操作的响应.结果的类型为 Microsoft.Azure.Client.ResourceResponse<T> ,其属性名为 RequestCharge .

You should be able to get that through .Net library. For example, take a look at the screenshot below which shows you the response of a Create New User operation. The result is of type Microsoft.Azure.Client.ResourceResponse<T> which has a property called RequestCharge.

更新

因此,我检查了查询结果,您正确的说这没有直接显示在.Net库中.但是,这在ResponseHeaders属性中可用,您可以使用类似以下的内容找到它:

So I checked the query result and you're correct that this is not exposed directly in the .Net library. However this is available in ResponseHeaders property and you could possibly find it out using something like below:

FeedResponse<Microsoft.Azure.Documents.Document> queryResult = await documentClient.CreateDocumentQuery<Microsoft.Azure.Documents.Document>(collectio‌​nSelfLink, query, options).AsDocumentQuery().ExecuteNextAsync<Microsoft.Azure.Documents.Document>(‌​);
var requestCharge = queryResult.ResponseHeaders["x-ms-request-charge"];

而不是在Fiddler中对其进行检查.

instead of inspecting it in Fiddler.

注意

ExecuteNextAsync可能会返回带有延续令牌的结果子集.如果要获得所有结果,则必须进行迭代,直到文档db不会发送abck连续令牌为止.

ExecuteNextAsync may return a subset of results with a continuation token. If you want all the results, you'd have to iterate till document db doesnt send abck a continuation token.

var docDbQueryable = documentClient.CreateDocumentQuery<Document>(collectio‌​nSelfLink, query, options).AsDocumentQuery();
var docDbResults = new List<Document>();
do
{
    var batchResult = await docDbQueryable.ExecuteNextAsync<Document>(‌​);;
    docDbResults.AddRange(batchResult);
}
while (docDbQueryable.HasMoreResults);
return docDbResults;

这篇关于通过.NET确定每个查询的DocumentDB请求费用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆