OK, obviously I'm doing something wrong here. I'm trying to create a webservice and I want "dateShipped" to be optional which means in the WSDL, I want minOccurs="0"
[Serializable]
[XmlType]
public class CTShipment
{
[XmlElement(Order = 0, IsNullable=false)] public CTDeliveryMethod DeliveryMethod;
[XmlElement(Order = 1, IsNullable=false)] public CTShipmentAddress ShipmentAddress;
[XmlIgnore] public bool dateShippedSpecified;
[XmlElement(Order = 2, IsNullable=false)] public DateTime dateShipped;
}
I want the WSDL to be generated like this:
<xs:complexType name="CTShipment">
<xs:annotation>
<xs:documentation>All details for the shipment of a suborder.</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="DeliveryMethod" type="CTDeliveryMethod" nillable="false"/>
<xs:element name="ShipmentAddress" type="CTShipmentAddress" nillable="false"/>
<xs:element name="dateShipped" type="xs:dateTime" nillable="false" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
Instead what I am actually getting is this:
<xs:complexType name="CTShipment">
<xs:sequence>
<xs:element name="DeliveryMethod" nillable="true" type="tns:CTDeliveryMethod"/>
<xs:element name="ShipmentAddress" nillable="true" type="tns:CTShipmentAddress"/>
<xs:element name="dateShipped" type="xs:dateTime"/>
<xs:element name="dateShippedSpecified" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
According to several things I've read (including http://msdn.microsoft.com/en-us/library/zds0b35c%28v=vs.90%29.aspx) including the public bool "dateShippedSpecified" should make "dateShipped" optional (minOccurs=0). As you can see, not only is this not happening but "dateShippedSpecified" is showing up in the WSDL even though it is marked with "[XmlIgnore]". You may have noticed that there is another problem as well: even though I'm specifying "IsNullable=false", I still get nillable="true" in the WSDL.
That is no less than 4 problems I can't explain all related to the same thing:
How can I set minOccurs to 0 in my WSDL?
Why isn't the [fieldName]Specified pattern making [fieldName] optional (minOccurs = 0)?
Even if it wasn't following the ___Specified pattern, why would dateShippedSpecified show up in the WSDL if it is marked with XmlIgnore?
Why is everything marked as nillable="true" even though I'm specifying "IsNullable=false"?
and as a bonus question, if anyone knows...
How do I get the annotation (as shown below) to be included?
<xs:annotation> <xs:documentation>All details for the shipment of a suborder.</xs:documentation> </xs:annotation>