无法获取 minOccurs=“1” maxOccurs=“1”对于 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 文件包含相应数据合同的以下信息:
<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>
有人可以让我知道我的数据合同中缺少什么以获得“模型”和“模型”的 minOccurs=1 和 maxOccurs=1 吗? Instrumentdata 类的“SerialNo”属性。
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:complexType>
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有关完整说明,请参阅此处 minOccurs 的确定方式。似乎对于引用类型,您必须指定
IsNullable=true
才能生成minOccurs=1
。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 produceminOccurs=1
.