对于DataContract中的字符串类型,无法获取minOccurs =“1”maxOccurs =“1”

时间:2011-09-26 06:39:21

标签: wcf xml-serialization datacontract

下面是我的WCF服务中的DataContract及其在wsdl文件中显示的相应xsd架构。

[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文件包含相应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:complexType>

有人可以让我知道我的数据合同中缺少什么,以获得“模型”&amp;的minOccurs = 1和maxOccurs = 1 Instrumentdata类的“SerialNo”属性。

1 个答案:

答案 0 :(得分:4)

有关确定minOccurs方式的完整说明,请参阅here。对于参考类型,您似乎必须指定IsNullable=true才能生成minOccurs=1