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
Anton Krouglov
  • 3,077
  • 2
  • 29
  • 50
  • Modify the set/get methods for DateTime in the serialization classes to do conversion. – jdweng May 31 '17 at 17:05
  • Class is generated so I would have to either extend svcutil or build my own – Anton Krouglov May 31 '17 at 17:08
  • How is class generate with a tool? So what the issue with editing the tool output? – jdweng May 31 '17 at 18:31
  • 1
    Since you're using `XmlSerializer` you could consider using a customized version of xsd.exe. See [XmlCodeExporter and nullable types](https://stackoverflow.com/q/42295155/3744182) which gives an idea of how to get started. – dbc May 31 '17 at 18:56
  • Yes if using tool. but you can compare using tool like beyond compare so you can merge edits. – jdweng May 31 '17 at 19:34
  • 1
    @dbc, thank you, indeed I can split wsdl into wsdl+xsd and use ether [xsd2code](https://xsd2code.codeplex.com/) or [codaxy/xsd2](https://github.com/codaxy/xsd2) or [WSCF](https://github.com/WSCF/WSCF) or play with xsd.exe sources. I will give it a try. – Anton Krouglov May 31 '17 at 22:42
  • @AntonKrouglov, have you found any solution? I'm in a similar situation. – ANewGuyInTown Apr 26 '22 at 05:01
  • @ANewGuyInTown as stated above - I have wrote custom utils based on xsd2code and svcutil – Anton Krouglov Apr 26 '22 at 07:55
  • @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? – ANewGuyInTown Apr 27 '22 at 00:14
  • @AntonKrouglov, a bit more details on what I want. https://stackoverflow.com/questions/72022016/extend-net-xmlserializer – ANewGuyInTown Apr 27 '22 at 00:51

0 Answers0