"System.Xml.XmlAttribute cannot be used as: 'xml element'." 而 运行 我的 asmx 服务

"System.Xml.XmlAttribute cannot be used as: 'xml element'." while running my asmx service

我正在尝试创建一个小型 asmx 服务,其方法会 return 一些虚拟数据。当我 运行 服务时出现以下错误: "System.InvalidOperationException: System.Xml.XmlAttribute cannot be used as: 'xml element'."

我的web方法如下:

[WebMethod]
public SubmitCaseRequestResponse1 SubmitCaseRequest(SubmitCaseRequestRequest1 request)
{

    var response = new SubmitCaseRequestResponse1
    {
        ResponseID = "456325898",
        Success = true,
        ValidationErrors = null

    };
    return response;
}

我的 SubmitCaseRequestResponse1 class:

public class SubmitCaseRequestResponse1

{ public 字符串 ResponseId { 得到;放; }

public bool Success { get; set; }

public ValidationError[] ValidationErrors { get; set; }

}

请求 class 是:

public class SubmitCaseRequestRequest1

{ public AuthHeader AuthHeader { 得到;放; }

public SubmitCaseRequestRequest PostCaseDateRequest { get; set; }

}

我应该序列化复杂类型 SubmitCaseRequestRequest1 和 SubmitCaseRequestResponse1 。需要为复杂类型添加 [XmlElement],为简单类型添加 [XmlAttribute]

[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://tempuri.org/")]
[Serializable]
public class SubmitCaseRequestRequest1
{
    [XmlElement]
    public AuthHeader AuthHeader { get; set; }

    [XmlElement]
    public SubmitCaseRequestRequest PostCaseDateRequest { get; set; }
}

[Serializable]
public class SubmitCaseRequestRequest
{
    [XmlElement]
    public Guid? RequestId { get; set; }
    [XmlAttribute]
    public string LCICourtNumber { get; set; }
    [XmlAttribute]
    public string CaseNumber { get; set; }
    [XmlAttribute]
    public string DebtorLastName { get; set; }
    [XmlAttribute]
    public string DateType { get; set; }
}