我需要调用第三方Web服务,该服务接受xml文件作为对象。
-<Claims>
-<Claim>
<ID>ID1</ID>
-<Person>
<ID>ID1</ID>
</Person>
-<Encounter>
<Type>1</Type>
</Encounter>
-<Diagnosis>
<CodeTerm>ICD10</CodeTerm>
<Type>Principal</Type>
<Code>A12.0</Code>
</Diagnosis>
-<Activity>
<ID>ID1</ID>
<CodeTerm>ADA</CodeTerm>
<Start>12/02/2013 12:12</Start>
<Code>84132</Code>
<Quantity>0</Quantity>
</Activity>
</Claim>
</Claims>
我创建了一个示例类并对该值进行了硬编码。在调用Web服务时获得以下异常。
**System.InvalidOperationException**
Additional information: There was an error generating the XML document.
Message: **The type CallingWebserviceTest.Claims was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.**
Code:
XDocument doc = XDocument.Load(FILENAME);
Claims c = new Claims();
List<ClaimsClaim> c1 = new List<ClaimsClaim>();
ClaimsClaim cc = new ClaimsClaim();
cc.claimID = "ID1";
cc.personID = "ID1";
cc.encounterType = 1;
cc.codeTerm = "ICD10";
cc.codeType = "A12.0";
cc.activityID = "ID1";
cc.codeTerm = "ADA";
cc.start = "12/02/2013 12:12";
cc.activityCode = 84132;
cc.quantity = 0;
c1.Add(cc);
c.claims = c1;
Console.WriteLine(cc.personID);
Gway g = new Gway();
responseClaimEdit[] responce;
string msg;
Console.WriteLine(g.DCG("1", c, "NS028", "|N28", out responce, out msg).ToString());
Class:
[XmlInclude(typeof(ClaimsClaim))]
[Serializable]
[XmlRoot]
public class Claims
{
public List<ClaimsClaim> claims { get; set; }
}
[Serializable]
public class ClaimsClaim
{
public string claimID { get; set; }
public string personID { get; set; }
public int encounterType { get; set; }
public string codeTerm { get; set; }
public string codeType { get; set; }
public string code { get; set; }
public string activityID { get; set; }
public string activityCodeTerm { get; set; }
public string start { get; set; }
public int activityCode { get; set; }
public int quantity { get; set; }
}
有人可以帮忙吗?无法在Web服务中进行任何更改。
答案 0 :(得分:0)
XDocument类是否可能希望XML文件具有标准XML标头,如下所示:
<?xml version="1.0" encoding="UTF-8"?>