Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make WCF service use a specific DataContractSerializer constructor overload?

DataContractSerializer has many constructor overloads, and I'd like to be able to specify how my WCF service should initialize the DataContractSerializer it uses. How would you go about doing this? Is it easier to configure this in the .config file or in C#?

A WCF service always appears to use this one by default.

If possible, please give an example of how to specify DataContractSerializer using this constructor for KnownTypes.

like image 212
T. Webster Avatar asked Oct 10 '22 23:10

T. Webster


2 Answers

This MSDN forum post shows how to swap the serializer in WCF with another. You could create your own wrapper with the constructor that you want and swap it in.

like image 65
Sixto Saez Avatar answered Nov 09 '22 05:11

Sixto Saez


I figured out how to do this. See

http://blogs.msdn.com/b/youssefm/archive/2009/06/05/introducing-a-new-datacontractserializer-feature-the-datacontractresolver.aspx

and

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer(v=vs.85).aspx

for guidance. Hope this helps.

like image 34
T. Webster Avatar answered Nov 09 '22 05:11

T. Webster