如何在 Silverlight WCF 生成的服务中使用 protobuf-net [英] How do I use protobuf-net in Silverlight WCF generated service

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

问题描述

我尝试在 WCF/Silverlight 应用程序中使用 protobuf-net 来提高大对象数组序列化性能.我可以在服务代码中序列化/反序列化类(添加 Order= 等).

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.

但是当我尝试应用 ProtoBehavior 并从 Silverlight 调用支持 protobuf 的服务方法时,我得到的是空值而不是数据(或错误).

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

我认为这是因为:

  1. ProtoBehavior 在 Silverlight 生成的服务代码中丢失;
  2. 域类(类型)不在重复使用的程序集中,它们在客户端重新生成并且 Order= 丢失.

但是目前我不能改变这两点.有没有办法在不重构(相当大的)项目的情况下使用 protobuf-net 以与域类等共享 ASP.NET/Silverlight 程序集?

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?

我什至认为调整 Reference.cs 以将缺失的行为和 Order= 添加到适当的成员(通过 perl/regex 脚本)会更容易,如果没有其他解决方案,但我到底需要调整什么,并且将有用吗?

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?

推荐答案

Re [ProtoBehavior],Silverlight 缺乏我们可以用来静默注入的扩展点WCF 中的替代序列化程序,这很痛苦.目前使用 silverlight 执行此操作的唯一方法是通过网络抛出 byte[]Stream,并处理序列化/两端反序列化.

Re [ProtoBehavior], Silverlight quite simply lacks the extension points that we can use to silently inject an alternative serializer into WCF, which is a pain. The only ways of doing this currently with silverlight are to throw either a byte[] or a Stream over the wire, and handle the serialization / deserialization at the two ends.

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

Re Order=..., it would be worth checking the contents; if they are coming up with different numbers, there are ways to fix this via a partial class - an ugly hack, but IIRC there is ProtoPartialMember (or similar) that can be applied to the class, but which talks about an individual member (property/field). You can correct the number this way. There is also an Offset (IIRC, sorry - no code to hand) on [ProtoContract] which can also help if you have large numbers of fields.

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

In v2 (not released) you can take much better control of the ordering (/field numbers) without having to mess with attributes.

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

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