I am using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, with hotfix
82202, Visual studio .NET 2003 with hotfix 823639.
I have generated a proxy class using wsdl.exe from a schema that has an
xsd:date element called XYZ_IncDate.
<xsd:attribute name="XYZ_IncDate" type="xsd:date" use="required">
If I change the xsd:date element to be optional, then wsdl.exe generates two
attributes for the date field in the proxy class:
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="date")]
public System.DateTime XYZ_IncDate;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool XYZ_IncDateSpecified;
If the element is required, then it only generates one attribute.
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="date")]
public System.DateTime XYZ_IncDate;
The problem I am having is, when the element is required, it is not
serialized in the XML, and my web service request fails because this element
really is required, and it's not there. I can verify that that value is
being set in the proxy class, but it does not appear in the XML. When the
element is optional, I can force the attribute to appear in the XML by
setting the XYZ_IncDateSpecified to true, but I don't have that option in the
case where the attribute is required, because no XYZ_IncDateSpecified
attribute is created in the proxy.
It seems to me that the behavior in XML serialization for the case where the
element is required is exactly the opposite of what it should be. I can
understand not needing the XYZ_IncDateSpecified flag, because if it's
required it should always be serialized in the XML. But the opposite is
happening! It is never serialized in the XML, and you are not even given the
option to try to force it to serialize the value via the
XYZ_IncDateSpecified, as you can when it is optional. Is this a known bug in
XML serialization, and does anyone know what can be done to fix/work around
this without requiring manual editing of schema and proxy classes?
The trouble is, we need to have a solution that works for people who are
generating their XML schemas on the fly based on their data types - it is up
to their discretion whether certain attributes of their data are required or
not. Once they have created their datatype, we generate a schema which obeys
their wishes as far as whether certain elements are required or not, and we
create a wsdl referencing their schema for their data type. It's not just a
matter of tweaking one schema or one proxy class. We want to be able to have
users generate their schema and wsdl, generate the proxy, and run, without
having to do manual edits on the proxy class.
--
Cindy