在 WCF 服务中使用 protobuf [英] Using protobuf in WCF services

查看:30
本文介绍了在 WCF 服务中使用 protobuf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 asp.net 网页位于 IIS Web 服务器上,它使用基本的 HTTP 绑定与 WCF 服务(位于 Windows 2008 应用服务器上)进行通信.我的 wcf 服务的性能似乎没有那么好,我想改进它.此外,我需要平衡可扩展性,因为我的网站将拥有非常高的流量.

My asp.net web pages are on IIS web server and it communicates with WCF services(sitting on windows 2008 app server) using basic HTTP binding. The performance of my wcf services doesnt seem to be that good and I want to improve the same.Also, I need to balance on scalability as my site will be having a very high traffic.

HTTP 压缩、节流是我知道但还没有尝试过的一些方法..我可以使用 protobuf API 吗...请建议...

HTTP compression,throttling are some of the ways am aware of but have not tried them yet.. Can i use protobuf API...Please suggest...

推荐答案

简短的回答是是"...

The short answer is "yes"...

protocol buffers 规范本身不提供 RPC 堆栈,但已在规范之外添加了一些.

The protocol buffers spec itself doesn't provide an RPC stack, but some have been added outside the spec.

首先,protobuf-net 有 WCF 的钩子,允许你标记操作在您的服务合同中作为 ProtoBehavior.然后将常规的 DataContractSerializer 交换为使用 protobuf-net 序列化.但是,有一些警告:

Firstly, protobuf-net has hooks for WCF, allowing you to mark operations on your service contract as ProtoBehavior. This then swaps the regular DataContractSerializer to use protobuf-net serialization. However, there are some caveats:

  • 您的数据成员必须具有明确的顺序(例如 [ProtoMember(Order = 1)]),因为它使用这些数字作为字段标识符(协议缓冲区使用数字字段)
  • 它最适用于程序集/类共享(服务合同等),因为此自定义行为未在mex"上公开
  • your data-members must have explicit Order (e.g. [ProtoMember(Order = 1)]), since it uses these numbers as the field identifiers (protocol buffers uses numeric fields)
  • it works best with assembly/class sharing (of the service contract etc), since this custom behavior is not exposed on "mex"

当与基本的 http 传输一起使用时,这也与 MTOM(如果启用)兼容以实现最大吞吐量.非平凡消息的性能在很大程度上与其大小成正比;您可以在此处了解 protobuf-net 的大小.

When used with the basic http transport, this is also compatible with MTOM (if enabled) for maximum througput. Performance of non-trivial messages is largely proportional to their size; you can get an idea of protobuf-net's sizes here.

或者,我也在研究定制的 RPC 堆栈.当前版本 有一个通过 http 的工作栈,但我也计划当我有机会时,在原始 TCP/IP 上启用它.我还没有机会写出来,但我可以根据要求提供示例.请注意,为了最方便地使用它,您还需要 3.5扩展"dll.

Alternatively, I'm also working on a bespoke RPC stack. The current build has a working stack over http, but I also plan to enable it on raw TCP/IP when I get chance. I haven't had chance to write it up yet, but I can provide examples on request. Note that to use it most conveniently, you'll want the 3.5 "extensions" dll, too.

如有任何问题,请添加评论或给我发电子邮件(请参阅我的个人资料).

Any questions, add a comment or e-mail me (see my profile).

这篇关于在 WCF 服务中使用 protobuf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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