0

我正在创建 WCF 服务,这里是服务的 DataContract 部分,我将Fromdate字段设置为必需属性。

[DataContract(Name = "PriceCalculationRequest")]
    public class PriceReq
    {
        [DataMember(Name = "PickupDate", Order = 1, IsRequired = true , EmitDefaultValue=true)]
        private DateTime FromDate { get; set; }

        [DataMember(Name = "ReturnDate", Order = 3)]
        public DateTime ToDate { get; set; }

        [DataMember(Order = 2)]
        public string PickupLocation { get; set; }

        [DataMember(Order = 4)]
        public string ReturnLocation { get; set; }

        public string CarType { get; set; }
    }

这是wsdl从上面的代码生成的文件,我怎样才能确定哪个属性是必需的属性,

<xs:sequence>
<xs:element minOccurs="0" name="pickupDate" type="xs:dateTime"/>
<xs:element minOccurs="0" name="returnDate" type="xs:dateTime"/>
<xs:element minOccurs="0" name="pickupLocation" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="vehiclePreference" nillable="true" type="xs:string"/>
</xs:sequence>
4

2 回答 2

1

确保在进行修改后重建您的服务项目。这就是我得到的:

<xs:sequence>
    <xs:element name="PickupDate" type="xs:dateTime"/>
    <xs:element minOccurs="0" name="PickupLocation" nillable="true" type="xs:string"/>
    <xs:element minOccurs="0" name="ReturnDate" type="xs:dateTime"/>
    <xs:element minOccurs="0" name="ReturnLocation" nillable="true" type="xs:string"/>
</xs:sequence>
于 2013-07-03T13:01:00.573 回答
0

如果您设置 IsRequired=true 它显示 minoccurs="0" 表示它是必需的

minOccurs="0"

请参阅此链接以获取说明:http ://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints

于 2013-07-03T13:20:42.367 回答