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

帅比萌擦擦* 提交于 2020-01-17 08:44:09

问题


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

来源:https://stackoverflow.com/questions/44290214/contract-first-wcf-soap-development-controlling-over-primitive-types-xml-serial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!