An open plea to Microsoft to fix the serializers in WCF.
- by Scott Wojan
I simply DO NOT understand how Microsoft can be this far along with a tool like WCF and it STILL tout it as being an "Enterprise" tool.
For example... The following is a simple xsd schema with a VERY simple data contract that any enterprise would expect an "enterprise system" to be able to handle:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Sample"
targetNamespace="http://tempuri.org/Sample.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/Sample.xsd"
xmlns:mstns="http://tempuri.org/Sample.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SomeDataElement">
<xs:annotation>
<xs:documentation>This documents the data element. This sure would be nice for consumers to see!</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Description" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
<xs:attribute name="IPAddress" use="required">
<xs:annotation>
<xs:documentation>Another explanation! WOW!</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
An minimal example xml document would be:
<?xml version="1.0"encoding="utf-8" ?>
<SomeDataElementxmlns="http://tempuri.org/Sample.xsd" IPAddress="1.1.168.10">
</SomeDataElement>
With the max example being:
<?xml version="1.0"encoding="utf-8" ?>
<SomeDataElementxmlns="http://tempuri.org/Sample.xsd" IPAddress="1.1.168.10">
<Description>ddd</Description>
</SomeDataElement>
This schema simply CANNOT be exposed by WCF.
Let's list why:
svcutil.exe will not generate classes for you because it can't read an xsd with xs:annotation.
Even if you remove the documentation, the DataContractSerializer DOES NOT support attributes so IPAddress would become an element this not meeting the contract
xsd.exe could generate classes but it is a very legacy tool, generates legacy code, and you still suffer from the following issues:
NONE of the serializers support emitting of the xs:annotation documentation. You'd think a consumer would really like to have as much documentation as possible!
NONE of the serializers support the enforcement of xs:restriction so you can forget about the xs:minLength, xs:maxLength, or xs:pattern enforcement.
Microsoft... please, please, please, please look at putting the work into your serializers so that they support the very basics of designing enterprise data contracts!!