是否有内置方法来确定 WCF 响应的大小?

发布于 2024-08-31 01:30:47 字数 228 浏览 0 评论 0原文

在客户端获得 Web 请求的完整有效负载之前,我们希望首先向其发送对其将获得的响应大小的测量。如果响应太大,客户端将向用户显示一条消息,让他们选择中止操作。

我们可以编写一些自定义代码来在服务器上预加载响应,确定大小,然后将其传递给客户端,但如果有其他方法可以做到这一点,我们宁愿不这样做。

有谁知道 WCF 是否有任何棘手的方法来做到这一点?或者有没有免费的第三方工具可以完成此任务?

谢谢。

Before a client gets the full payload of the web request, we'd like to first send it a measurement of the size of the response it will get. If the response will be too large, the client will present a message to the user giving them the option to abort the operation.

We can write some custom code to preload the response on the server, determine the size, and then pass it on to the client, but we'd rather not if there's another way to do it.

Does anyone know if WCF has any tricky way to do this? Or are there any free third party tools out there that will accomplish this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2024-09-07 01:30:47

我不认为 WCF 或 .NET 框架中有什么“棘手”的东西可以做到这一点,真的。你要传回给客户端什么?一个类的实例?

您可以做的是运行查询,或者无论如何获取响应,然后将其序列化到内存流中并查看它有多大。这不会是一个完全准确的大小 - SOAP 消息有一些开销,如 SOAP 信封和标头等 - 但它可以为您提供一个大概的数字,表明您是否要返回几百个字节,或者一个几兆字节。

问题是:这可能需要在服务器上花费一段时间来组装/查询,然后再实际“测量”。另外,您几乎必须进行两次调用 - 一次调用“MeasureResult”,返回 Int 或 Long 或其他值,然后第二次调用“GetResult”以实际获取结果。因此,您将花费两次精力来组装消息......

我真的没有一个好的答案给您,但也许您只需要找出其他方法来允许客户端在需要时中止呼叫太长了。或者找到一种方法来更快地找出响应有多大的指标(无需获取响应本身的所有详细信息)。

I don't think there's anything "tricky" in WCF or the .NET framework to do this, really. What are you passing back to the client? An instance of a class?

What you could do is run the query or however you fetch the response, and then serialize that into a memory stream and see how big it gets. This won't be a totally accurate size - the SOAP messages has some overhead to it, like SOAP envelope and headers and stuff - but it can give you a ballpark figure of whether you're about to return a few hundred bytes, or a couple megabytes.

Trouble is: this might take a while on the server just to assemble / query, and then to actually "measure", too. Plus you'd almost have to have two calls - one to "MeasureResult" which returns an Int or Long or something, and then a second call "GetResult" to actually get the results. So you'll incur that effort to assemble the message twice....

I don't really have a good answer for you, but maybe you just need to figure out some other way to allow the client to abort a call if it takes too long. Or find a way to more quickly figure out an indicator as to how large the response will be (without getting all the details of the response itself).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文