Google Protocol Buffers 或类似的 .net/javascript 的东西
我们当前使用 Ajax 调用 .net Web 服务,然后将 Json 对象返回给客户端。 其中一些 Json 对象非常庞大(未压缩时> 500k)。 我们听说过一些关于 Google Protocol Buffers 的好消息,并且一直在进行试验。
到目前为止,我们在服务器上使用最常见的 .net 版本“protobuf-net”进行序列化的运气非常好。 我们在客户端反序列化方面运气不佳。 我们尝试使用似乎是唯一的 JavaScript 反序列化器 protobuf.js。 我们发现它不容易使用,示例或文档很少,而且它似乎不处理字符串和整数之外的数据类型。
看来此时,.net 和 Web 客户端之间的二进制数据序列化/反序列化将有一个经过验证的、定义良好的解决方案。 也许我们遗漏了一些明显的东西。
我们的要求是来自客户端的 Ajax 调用以及服务器上的 .net Web 服务方法(.asmx 或 WCF)。
如有任何意见和建议,我们将不胜感激。
We are currently using Ajax calls to a .net web service that then returns a Json object to the client. Some of these Json objects are pretty massive (> 500k uncompressed). We have heard some good things about Google Protocol Buffers and have been experimenting.
So far, we have had pretty good luck serializing on the server with what seems to be the most common .net version - "protobuf-net". We have not had much luck deserializing on the client. We tried using what seems to be the one and only javascript deserializer protobuf.js. We found that it is not easy to use, there are very few examples or documentation, and it does not seem to handle datatypes beyond strings and ints.
It would seems that at this point, there would be a proven, well defined solution for binary data serialization/deserialization between .net and a web client. Maybe we are missing something obvious.
Our requirements are Ajax calls from the client, and .net web services methods on the server (.asmx or WCF).
Any comments and suggestions are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果客户端是javascript,我想你会很困难。 (正如您所说)JavaScript 的覆盖范围有限,但我不确定它会给您带来很多好处。 引用 Kenton Varda(谁真正了解protobuf):
所以也许未来还有希望。 现在我会坚持使用 json + deflate,或者如果您的场景允许,您也许可以使用嵌入在客户端中的 Silverlight 小程序? protobuf-net 将在 Silverlight 中工作。
If the client is javascript, I think you'll struggle. There is (as you've stated) limited javascript coverage, but I'm not sure it will gain you a lot. To quote from Kenton Varda (who really knows protobuf):
So maybe there is hope down the road. For now I would stick with json + deflate, or if your scenario allows it you could perhaps use a Silverlight applet embedded in the client? protobuf-net will work inside Silverlight.
您可能会发现 JSON 实际上是最好的答案。 Justin 做了一系列JSON 与 Thrift 和 Protocol Buffers 的性能比较,并发现压缩的 JSON比protocol buffers更快,至少在Python中是这样。 这是关于该主题的早期线程。
You may find JSON is in fact the best answer. Justin has done a series of performance comparisons of JSON to Thrift and Protocol Buffers and found compressed JSON to be faster than protocol buffers, at least in Python. Here's an earlier thread on the topic.
如前所述,使用 javascript 的二进制协议是有问题的。 一些特别令人讨厌的方面是:
而且与 JSON 或 XML 的本机支持相比,性能不太可能更快。
As mentioned, using binary protocols from javascript is problematic. Some specifically nasty aspects are:
And performance is very unlikely to be faster, compared to native support for JSON or XML.