0

After creating a service reference in VS2013 - using XmlSerializer, one property in the auto-generated classes is decorated with DefaultValueAttribute("UTF-8").

If I set the property to something different than "UTF-8", the property gets serialized in the request as expected. But if I set it to the default value "UTF-8", the property is not serialized.

I get that this is the functionality to expect from XmlSerializer, but the problem is that that the company hosting the service insists that we include the property in the request.

So my question is: Is there any way to force the serialization of a property with default value, or alternative, not to include the DefaultValueAttribute during generation of service reference classes?

Kayak58
  • 41
  • 7
  • what are you using for serialization `DataContract` ? – Ameya Deshpande Oct 06 '16 at 12:04
  • Do any of the solutions here work for you? [How to tell XmlSerializer to serialize properties with `[DefautValue(…)]` always?](https://stackoverflow.com/questions/15357589/how-to-tell-xmlserializer-to-serialize-properties-with-defautvalue-always) – dbc Oct 06 '16 at 17:02
  • Or here: [Force XML serialization of XmlDefaultValue values](https://stackoverflow.com/questions/28054335/force-xml-serialization-of-xmldefaultvalue-values). – dbc Oct 06 '16 at 17:17
  • What I understand from these suggestions, is that a solution would be to add a IClientMessageFormatter implementation which uses a custom serializer. I thought maybe there would be a cleaner way. My current workaround is to modify the request Message in IMessageInspector. – Kayak58 Oct 07 '16 at 07:48

0 Answers0