很抱歉,一个非常简单的问题,我似乎找不到答案。我正在尝试为WCF服务编写数据合同以接收以下xml:
<?xml version="1.0"?>
<CachedAwiData QReference="3" QAttempt="0" QReservation="{D6154D1C-6D42-4AA5-9FAC-217B2F9FE096}">
<CachedAwiDataRecord>
<CustRef><![CDATA[1]]></CustRef>
<Details><![CDATA[Hello World]]></Details>
<PrefDay><![CDATA[Monday]]></PrefDay>
<PrefTime><![CDATA[8.00am - 9.00am]]></PrefTime>
<Priority><![CDATA[Urgent]]></Priority>
<Trade><![CDATA[Plasterer]]></Trade>
</CachedAwiDataRecord>
</CachedAwiData>
到目前为止,我已经尝试了几件事,并且达到了:
[DataContract(Namespace = "")]
public class CachedAwiData
{
}
[DataContract(Namespace = "")]
public class CachedAwiDataRecord : CachedAwiData
{
[DataMember]
public string CustRef { get; set; }
}
我得到的响应似乎为CustRef提供了一个空值:
<ResponseData xmlns="http://schemas.datacontract.org/2004/07/RestService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><CustRef i:nil="true" /></ResponseData>
我假设它与DataContract有关,但也许我在这里遗漏了一些东西。非常感谢任何线索,还是我最好回到XML Serializer?
答案 0 :(得分:0)
我认为继承不正确。我使用DataContracts的次数不多,但我认为您需要类似的东西
[DataContract(Namespace = "")]
public class CachedAwiData
{
[DataMember]
public CachedAwiDataRecord DataRecord;
}
[DataContract(Namespace = "")]
public class CachedAwiDataRecord
{
[DataMember]
public string CustRef { get; set; }
}