2

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:

  1. How can I set minOccurs to 0 in my WSDL?

  2. Why isn't the [fieldName]Specified pattern making [fieldName] optional (minOccurs = 0)?

  3. Even if it wasn't following the ___Specified pattern, why would dateShippedSpecified show up in the WSDL if it is marked with XmlIgnore?

  4. Why is everything marked as nillable="true" even though I'm specifying "IsNullable=false"?

    and as a bonus question, if anyone knows...

  5. 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>
    
4

2 回答 2

2

这是 .net 实现中的一个错误。

根据 W3C 规范(对于 wsdl) minOccurs="0" 可以在序列中使用。“<序列>”表示按顺序出现0次或多次的元素。

例如查看官方 W3C 对 wsdl 的定义:http: //www.w3.org/TR/wsdl

您将看到以下元素:

<sequence>
         <element ref="wsdl:documentation" minOccurs="0"/>
 </sequence>

现在何时需要与 .Net 兼容,使用 nillable="true" 这会给你 DateTime?(可为空的版本)而不是 DateTime。

于 2014-05-30T17:24:51.357 回答
1

这是由于序列元素。它指定每个元素的 minOccurs= 1。并且 WSDL 使用 Sequence-Element 而不是“All”,因为您为它们指定了 Order。这要求每个值都存在。

因此,当您删除订单时,它应该可以正常工作。如果您真的需要订单,那么您将无法忽略该值。

于 2013-05-30T13:37:22.073 回答