在wcf中设置强制字符串datamember

时间:2015-05-26 06:38:54

标签: wcf wcf-data-services datacontract

我想将字符串DataMember设置为必需,我已设置" IsRequired = true"但它在XML请求中显示为可选。

[MessageContract(WrapperName = "tourinforequest")]
public class TourInfoRequest
{
    public TourInfoRequest()
    {
        Request = new TourInfoRequestRequestData();
    }
    [MessageBodyMember]
    public TourInfoRequestRequestData Request;
}

public class TourInfoRequestRequestData : BaseRequest
{
    [DataMember(Order = 1, IsRequired = true ), XmlElement(ElementName = "tourcode")]
    public string TourCode { get; set; }

    [DataMember(Order = 2, IsRequired = true), XmlElement(ElementName = "depdate")]
    public DateTime DepartureDate { get; set; }
}

0 个答案:

没有答案