The problem is that WCF DataContract is an interoperable mechanism that can be used on different languages ββand platforms.
If you look at the serialized data generated by the DataContractSerializer (or its code in System.Runtime.Serialization.dll , namely the InternalWriteObjectXyz() methods), you will see that it simply serializes the values ββinto a simple XML message. There will be nothing related to the .NET Framework, so all kinds of attributes, both generated by the user and using the compiler, will be deleted and not even received by the client.
It creates a copy of your data and sends it from the server to the client, then the clients will create a new class with the same signature . Note: A NEW CLASS with the same signature is NOT ONLY A NEW OBJECT of the source class.
Of course, there is a workaround for this. You can write your own serializer (see this post in SO format for an example) or your own ISerializationSurrogate .
If you can deploy / share your assemblies for your clients, you have a good way: just deploy them, and the DataContractSerializer build the correct object on your clients (just like you had on the server with all its attributes). Just remember that:
- If user attributes come from runtime values ββ(for example, due to localization), they will be allowed on the client and not on the server (since the attributes will be created on the client, their values ββwill not be included in the XML message).
- In the client application, you need to add a link to the assembly containing your types.
- When you add a link to a service, you must tell VS to use them (or create a proxy), in the Help service settings dialog box, select Reuse types in reference assemblies (you can limit it only to the nodes you want to split).
Adriano repetti
source share