开发者

Could not get minOccurs="1" maxOccurs="1" for a string type in a DataContract

开发者 https://www.devze.com 2023-04-08 05:11 出处:网络
Below is a DataContract in my WCF service and its respective xsd schema shown in the wsdl file. [Serializable]

Below is a DataContract in my WCF service and its respective xsd schema shown in the wsdl file.

[Serializable]
[XmlRoot(Namespace = "http://www.example.com/l0257/services/mgnt/datatypes/0/1",IsNullable = false)]
public partial class InstrumentData
{
    private string _serialNo;
    private string _model;
    private int _pointsRecorded;

    [XmlElement(ElementName = "SerialNo", IsNullable = false)]
    public string SerialNo
    {
        get { return _serialNo; }
        set { _serialNo = value; }
    }

    [XmlElement(ElementName = "Model", IsNullable = false)]
    public string Model
    {
        get { return _model; }
        set { _model = value; }
    }

    [XmlElement(ElementName = "PointsRecorded", IsNullable = false)]
    public int PointsRecorded
    {
        get { return _pointsRecorded; }
        set { _pointsRecorded = value; }
    }
}

WSDl file contains the below info for the respective datacontract:

 <xs:complexType name="InstrumentData">
 <xs:sequence>
  <xs:element minOccurs="0" maxOccurs="1" name="SerialNo" type="xs:string" /> 
  <xs:element minOccurs="0" maxOccurs="1" name="Model" type="xs:string" /> 
  <xs:element minOccurs="1" maxOccurs="1" name="PointsRecorded" type="xs:int" /> 
  </xs:sequence>
  </xs:compl开发者_如何学JAVAexType>

Can someone please let me know what am I missing in my data-contract to get minOccurs=1 and maxOccurs=1 for the "Model" & "SerialNo" properties of Instrumentdata class.


See here for a full description of the way minOccurs is determined. It seems that for a reference type you must specify IsNullable=true in order to produce minOccurs=1.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号