views:

61

answers:

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?

+1  A: 

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=..., 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.

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

Marc Gravell
Right, for some reason generated Order= was lost only on first property in the generated reference.cs class, all others have it but with offset -1. Very strange. But now by fixing this and sending byte[] over the wire, I can get my data back. So, there's no way to use ProtoBehavior in Silverlight, have to stick to byte[]? Not that big deal, but still... since types are generated, this will take extra effort to force classes generation, and so on.
queen3
@queen3 - not that I know of. I do, however, know that somebody (not me) has been doing a lot of work on RPC for C#; maybe that will work within Silverlight as an *alternative* to WCF? I haven't had time to play with it yet.
Marc Gravell