Contract-First WCF SOAP development: controlling over primitive types XML serialization
Asked Answered
G

0

0

I am implementing C# WCF SOAP 1.1 service (server-side) from a given wsdl (contract first development). The problem I am facing is that there are additional (non-wsdl) formatting requirements for xsd:dateTime, xsd:decimal and xsd:time.

Contract generated by SvcUtil.exe performs standard XML serialization formatting dates and decimals a bit differently.

Given the sample SOAP messages provided my WCF service stub has no problems understanding and converting these formats. My responses however do contain extra information – time zone, milliseconds, extra digits after decimal.

Wsdl is huge – 100+ messages, 1000+ complex types. Primitive properties of complex types are mapped to XML attributes. It looks like it is originated from some java framework.

  1. Straighforward and ugly solution would be to postprocess SOAP with either RegExp or XSLT somewhere at OnWriteBodyContents or MessageFormatter.

  2. Expensive solution would be to build own code-from-wsdl builder that will produce extra string properties as described here.

  3. I have tried to find a way to customize XmlSerializer with either IXmlSerializable or proxy deserialize helper or custom value type. Neither solution worked. Only fixed list of primitive types can be put into xml attribute.

  4. So yet another expensive way would be to write own xml serializer as the .NET XmlSerializer is a black box and there is no way to control over primitive types serialization.

Any better ideas?


Format specification:

xsd:decimal: No more than two digits after decimal
xsd:dateTime: YYYY-MM-DDThh:mm:ss, no milliseconds, no time zone
xsd:time: hh:mm:ss.sss
xsd:date: YYYY-MM-DD
Godoy answered 31/5, 2017 at 16:33 Comment(10)
Modify the set/get methods for DateTime in the serialization classes to do conversion.Mame
Class is generated so I would have to either extend svcutil or build my ownGodoy
How is class generate with a tool? So what the issue with editing the tool output?Mame
Since you're using XmlSerializer you could consider using a customized version of xsd.exe. See XmlCodeExporter and nullable types which gives an idea of how to get started.Emmalineemmalyn
Yes if using tool. but you can compare using tool like beyond compare so you can merge edits.Mame
@dbc, thank you, indeed I can split wsdl into wsdl+xsd and use ether xsd2code or codaxy/xsd2 or WSCF or play with xsd.exe sources. I will give it a try.Godoy
@AntonKrouglov, have you found any solution? I'm in a similar situation.Pyxidium
@Pyxidium as stated above - I have wrote custom utils based on xsd2code and svcutilGodoy
@AntonKrouglov, I need to make use of the default serializer as it has many features but control deserialization of certain fields of a class. Since you have done similar, is there any recommendation you may have for this?Pyxidium
@AntonKrouglov, a bit more details on what I want. https://mcmap.net/q/591006/-extend-net-xmlserializerPyxidium

© 2022 - 2024 — McMap. All rights reserved.