问题
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.
Straighforward and ugly solution would be to postprocess SOAP with either RegExp or XSLT somewhere at OnWriteBodyContents or MessageFormatter.
Expensive solution would be to build own code-from-wsdl builder that will produce extra string properties as described here.
I have tried to find a way to customize
XmlSerializer
with eitherIXmlSerializable
or proxy deserialize helper or custom value type. Neither solution worked. Only fixed list of primitive types can be put into xml attribute.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