With "full" .NET to .NET WCF, then switching the serialization layer to use
protobuf-net can (depending on a few factors) be as simple as a
configuration file change:
http://marcgravell.blogspot.com/2009/11/controlling-wcf-protobuf-net-at.html

<http://marcgravell.blogspot.com/2009/11/controlling-wcf-protobuf-net-at.html>*Unfortunately*,
this doesn't apply to Silverlight since Silverlight lacks that extension
point. There is no *silent* way of switching the serializer for Silverlight.
Instead the main mechanism for this would instead resolve around exposing
(on your WCF API) binary data - either byte[] or Stream. You would, of
course, then have to serialize/deserialize manually. Nowhere near as elegant
as you can achieve in full .NET, but it still works. WCF essentially then
becomes a plumbing layer, rather than representing the actual data API.

On the topic of data-contracts, you have a few options - if you have
existing data-contracts of the type:

    [DataContract]
    public class MyData {
        [DataMember]
        public int Foo {get;set;}

        [DataMember]
        public string Bar {get;set;}
    }

then all that is required is to associate a unique number with each member
(unique within the type, if you see what I mean). This can be done using the
Order property:

    [DataContract]
    public class MyData {
        [DataMember(Order=1)]
        public int Foo {get;set;}

        [DataMember(Order=2)]
        public string Bar {get;set;}
    }

or using protobuf-net's own attributes:

    [ProtoContract]
    public class MyData {
        [ProtoMember(1)]
        public int Foo {get;set;}

        [ProtoMember(2)]
        public string Bar {get;set;}
    }

It is important that the client and server agree about the numbers.

Alternatively, if you *don't* have existing types you can also start from a
.proto file; the generator included with protobuf-net can emit suitable
types for you.

Re transport; if you are using WCF over HTTP, it is usually worthwhile
enable MTOM; but I can't recall whether this is supported under Silverlight.

Re serialization; if we assume you are throwing byte[] up and down the wire,
you should just need something like:

    MyData obj = new MyData { Foo = 123, Bar = "abc" };
    byte[] blob;
    using(var ms = new MemoryStream()) {
        Serializer.Serialize(ms,obj);
        blob = ms.ToArray();
    }

and then to deserialize:

    MyData obj;
    using(var ms = new MemoryStream(blob)) {
        obj = Serializer.Deserialize<MyData>(ms);
    }

That should cover the main points. If there are more questions, please let
me know.

Marc Gravell
(protobuf-net)



On 27 May 2010 05:52, vikram <vikramraj....@gmail.com> wrote:

> Hi,
>
> I am new to Protocol Buffer.
> I wanted to implement protocolbuffer for binary serialization for my
> WCF service.
>
> My requirement goes as given below:
>
> FrontEnd: SilverLight 3.0
> Middlelayer:  WCF Service (.NET 3.5)
>
> I would like to know what things need to be incoporate in my WCF
> service to implemement
> protobuf-net. (If possible provide an example it would be more
> helpful)
>
> Is there any addition things need to be handled while creating a proxy
> class for my WCF service or else i can use regular svcutil.exe for
> generate my proxy class.
> (If possible provide an example it would be more helpful)
>
> In frontEnd, how to i serialize/de-serialize object from my service
> call via proxy class.
> (If possible provide an example it would be more helpful)
>
> Thanxs in advance
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>


-- 
Regards,

Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to