【问题标题】:How to deserialize a nested xml using DataContractSerializer in wcf?如何在 wcf 中使用 DataContractSerializer 反序列化嵌套的 xml?
【发布时间】:2013-02-22 16:37:22
【问题描述】:

如何在 wcf 中使用 DataContractSerializer 反序列化嵌套的 xml? 示例 xml 是;

<smsPaidPhoneBookSearchResponse xmlns="http://callturksvc.alfion.com.tr">
    <webServiceResponseType>SUCCESS</webServiceResponseType>
    <clientQueryId>112628650000001078</clientQueryId>
    <phoneBookList>
        <phoneBook>
            <cityName>İstanbul</cityName>
            <districtName>Beşiktaş</districtName>
            <firstName>Şuayp</firstName>
            <lastModifiedDateTime>2013-03-06T16:05:59.508+02:00</lastModifiedDateTime>
            <lastName>Çiçek</lastName>
            <phoneBookTypeEnumValue>TURKCELL</phoneBookTypeEnumValue>
            <phoneNumberText>535357****</phoneNumberText>
        </phoneBook>
        <phoneBook>
            <cityName>İstanbul</cityName>
            <districtName>Beşiktaş</districtName>
            <firstName>Şuayp</firstName>
            <lastModifiedDateTime>2013-03-06T16:05:59.510+02:00</lastModifiedDateTime>
            <lastName>Çiçek</lastName>
            <phoneBookTypeEnumValue>TURKCELL</phoneBookTypeEnumValue>
            <phoneNumberText>535957****</phoneNumberText>
        </phoneBook>
    </phoneBookList>
</smsPaidPhoneBookSearchResponse>

我成功获得了这些值 (webServiceResponseType,clientQueryId),但我无法将 phoneBookList 作为 phoneBook 类的通用列表。例如:List&lt;phoneBook&gt;

有什么办法吗?

【问题讨论】:

    标签: asp.net wcf xml-deserialization


    【解决方案1】:

    一种简单的查找方法是在 C# 中创建一个类似的结构,然后将其序列化。这样你就会知道 xml 中有什么问题。根据我的经验,您是否在合同中将 phoneBookList 标记为 Array,然后使用正确的名称将 PhoneBook 标记为 Array Element?

    【讨论】:

    • 看到的事情是,当您使用 DataMemeber 属性标记它们并且不为其添加名称时,它的序列化程序将查找类名称的完全匹配。尝试为 DataMember 属性添加一个名称,例如 [DataMember(Name="phoneBook")],看看是否可行。
    猜你喜欢
    • 1970-01-01
    • 2014-08-31
    • 1970-01-01
    • 2013-06-01
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    相关资源
    最近更新 更多