C# – add a WCF DataContract to a complex type


I have a complex data type, including a number of functions, as well as the usual get and get methods. My life would be considerably easier if I could use WCF so my client can also use this data type.

Do I

  1. Ignore all the operations, putting [DataMemeber] only where needed.

  2. Put the class in question in a shared library assembly for both client and server to access.


PS. I realise that the question is probably not as well worded as it could be.

Best Solution

All that's transferred across the WCF boundary is what is serialized - which amounts to the class's state. The methods won't be. So if you need them to be available both sides, then you'll need a shared library as you suggest.

When you add a service reference, you have the option to reuse the data type, in which case WCF will deserialize into the shared class, complete with methods. But it's only the field values that have actually been transferred across the boundary.