sternr
sternr

Reputation: 6506

Force WCF to use NetDataContractSerializer\DataContractSerializer

How can I tell a certain WCF Service to use DataContractSerializer or NetDataContractSerializer?

Suppose I succeed, will the proxy generated automatically identify it and use the correct one?

Upvotes: 2

Views: 1477

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

DataContractSerializer is used by default. On the service side you can control used serializers with behaviors. By default you have available DataContractFormat and XmlSerializerFormat attributes for this. These attributes can be applied on service contract, service implementation or on operations. On client side svcutil will use data contract serialization if types description are serializable by DataContractSerializer otherwise it will use XmlSerializer.

NetDataContractSerializer doesn't have behaviour prepared - you must create it yourselves. It is also not recognized by clients because when you use NetDataContractSerializer you will share assemblies with types (data contracts, service contracts) with client so you can share behaviour as well and mark service contract with that behaviour directly.

Upvotes: 3

Related Questions