1

I try to use protobuf-net in WCF/Silverlight application to improve large objects array serialization performance. I can serialize/deserialize classes (added Order=, etc) in the service code.

But when I try to apply ProtoBehavior, and call the protobuf-enabled service method from Silverlight, I get nulls instead of data (or errors).

I think this is because:

  1. ProtoBehavior is lost in Silverlight-generated service code;
  2. Domain classes (types) are not in the re-used assembly, they're regenerated on the client and Order= is lost.

However at present time I can't change both points. Is there a way to use protobuf-net without refactoring the (pretty big) project to have shared ASP.NET/Silverlight assembly with domain classes, etc?

I even think it will be easier to tweak Reference.cs to add missing behavior and Order= to appropriate members (via perl/regex script), if there's no other solution, but what exactly do I need to tweak, and will it work?

4

1 回答 1

1

重新[ProtoBehavior],Silverlight 完全缺少我们可以用来将替代序列化程序静默注入 WCF 的扩展点,这很痛苦。目前使用 silverlight执行此操作的唯一方法是将 abyte[]或 a扔到Stream电线上,并在两端处理序列化/反序列化。

Re Order=...,值得检查内容;如果他们想出不同的数字,有办法通过一个partial class丑陋的黑客来解决这个问题,但是 IIRC 有ProtoPartialMember(或类似的)可以应用于,但它谈论的是单个成员(属性/字段) . 您可以通过这种方式更正数字。如果您有大量字段,还有一个Offset(IIRC,抱歉 - 手头没有代码)[ProtoContract]也可以提供帮助。

在 v2(未发布)中,您可以更好地控制排序(/字段编号),而不必弄乱属性。

于 2010-09-09T09:15:59.510 回答