I used DataContractResolver before; and these are my conclusions:
- Both client and server require permission; as serialization and deserialization occur at both ends. Obviously, the same Resolver is used.
- Type names are a standard piece of information that the DataContractSerializer produces. However, this is a name of type NAME, and not the full (assembly) qualified name
Basically, a custom resolver allows you to add it to the WCF client and server as a βBehaviorβ:
`foreach (OperationDescription operation in myWCFService.Description.Endpoints[0].Contract.Operations) { operation.Behaviors.Find<DataContractSerializerOperationBehavior>() .DataContractResolver = new MyDataContractResolver(); }`
For the client, you do the same:
`foreach (var operation in base.ChannelFactory.Endpoint.Contract.Operations) { operation.Behaviors.Find<DataContractSerializerOperationBehavior>() .DataContractResolver = new MyDataContractResolver(); }`
My resolver dynamically loads types from a configured location and caches them based on some attribute. I can provide you with sample code if you want - it's all pretty simple.
KnownTypeAttribute (for example, using the provided method to return all known types) can also be used; but a custom resolver allows a more flexible approach, such as dynamically loading types (for example, a plug-in system) and performing its own mapping (Type => type name and vice versa)
NoDaldPrutm
source share