【问题标题】:wcf how to set not nullable DataMember for SOAP Web Servicewcf 如何为 SOAP Web 服务设置不可为空的 DataMember
【发布时间】:2019-04-15 02:40:23
【问题描述】:

我正在实施 wcf 服务。 我的班级结构如下:

[DataContract]
public class NotificationsSapInfo
{
    [DataMember]
    [Required]
    [StringLength(3)] 
    public string ID_CLIENT { get; set; }
    [DataMember]
    [Required]
    [StringLength(60)]
    public string ID_OBJECT_CODE { get; set; }
    [DataMember]
    [Required]
    [StringLength(60)]
    public string ID_TYPE { get; set; }
    [DataMember]
    [StringLength(60)]
    public string ID_SUB_TYPE { get; set; }
    [DataMember]
    [StringLength(4)]
    public string ID_DIVISION { get; set; }
    [DataMember]
    [StringLength(50)]
    public string ID_LINE { get; set; }
}

出现的问题是在生成的 WSDL 中似乎忽略了 RequiredStringLength 属性。

这是生成的 WSDL 部分。

<xs:complexType name="NotificationsSapInfo">

<xs:sequence>

<xs:element name="ID_CLIENT" type="xs:string" nillable="true" minOccurs="0"/>

<xs:element name="ID_DIVISION" type="xs:string" nillable="true" minOccurs="0"/>

<xs:element name="ID_LINE" type="xs:string" nillable="true" minOccurs="0"/>

<xs:element name="ID_OBJECT_CODE" type="xs:string" nillable="true" minOccurs="0"/>

<xs:element name="ID_SUB_TYPE" type="xs:string" nillable="true" minOccurs="0"/>

<xs:element name="ID_TYPE" type="xs:string" nillable="true" minOccurs="0"/>

</xs:sequence>

</xs:complexType>

我错过了什么?

提前致谢

【问题讨论】:

    标签: c# web-services wcf soap wsdl


    【解决方案1】:

    不确定这是否适用于您的情况,但我将其用于数据合同和数据验证:

    在您的 DataMember 属性上尝试添加:IsRequired = true

    [DataMember(IsRequired = true)]
    

    【讨论】:

    猜你喜欢
    • 2018-07-22
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多