我正在尝试使用一种方法创建一个小的asmx服务,该方法将返回一些虚拟数据。运行服务时出现以下错误: " System.InvalidOperationException:System.Xml.XmlAttribute不能用作:' xml元素'。"
我的网络方法如下:
[WebMethod]
public SubmitCaseRequestResponse1 SubmitCaseRequest(SubmitCaseRequestRequest1 request)
{
var response = new SubmitCaseRequestResponse1
{
ResponseID = "456325898",
Success = true,
ValidationErrors = null
};
return response;
}
我的SubmitCaseRequestResponse1类:
public class SubmitCaseRequestResponse1
{ public string ResponseId {get;组; }
public bool Success { get; set; }
public ValidationError[] ValidationErrors { get; set; }
}
,请求类是:
public class SubmitCaseRequestRequest1
{ public AuthHeader AuthHeader {get;组; }
public SubmitCaseRequestRequest PostCaseDateRequest { get; set; }
}
答案 0 :(得分:0)
我应该序列化复杂类型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; }
}