O'Reilly logo

Programming WCF Services, 2nd Edition by Juval Lowy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Serialization

The data contract is part of the contractual obligation the service supports, just like the service operations are part of that contract. The data contract is published in the service's metadata, allowing clients to convert the neutral, technology-agnostic representation of the data types to their native representations. Because objects and local references are CLR concepts, you cannot pass CLR objects and references to and from a WCF service operation. Allowing you to do so not only would violate the core service-oriented principle discussed previously, but also would be impractical, since an object is comprised of both its state and the code manipulating it. There is no way of sending the code or the logic as part of a C# or Visual Basic method invocation, let alone marshaling it to another platform and technology. In fact, when passing an object (or a value type) as an operation parameter, all you really need to send is the state of that object, and you let the receiving side convert it back to its own native representation. Such an approach for passing state around is called marshaling by value. The easiest way to perform marshaling by value is to rely on the built-in support most platforms (.NET included) offer for serialization. The approach is simple enough, as shown in Figure 3-1.

Serialization and deserialization during an operation call

Figure 3-1. Serialization and deserialization during an operation call

On the client ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required