0

我无法将一些 XML 反序列化为适当的对象结构。当我调用ReadObject(stream)DataContractSerializer时,它返回一个空数组。没有错误,不为空,只是一个空数组。

故事

我正在使用第 3 方服务,他们提供了 wsdl。我已将 wsdl 作为服务引用添加到我的项目中。我已成功调用此服务并收到响应,该响应已由 .Net 正确反序列化。所以我知道响应能够被反序列化。

我调用了一次服务以获取一些初始数据。然后,当第 3 方更新该数据时,他们将使用服务返回的相同响应 XML POST 到 MVC URL。当我尝试从 Request.InputStream 反序列化 XML 时,我得到一个空数组。

我已经搜索和搜索,但显然不是在正确的地方,因为我完全空白。

我真的很感激你能提供的任何方向。

以下是正在播放的代码和文件:

我的反序列化代码- 非常简单的东西,不是吗?updatedData是有问题的空数组。

    var dcs = new DataContractSerializer(typeof(IEnumerable<Account1>),
        "ListOfIrstAccountBrandAccountResponseIo",
        "http://www.siebel.com/xml/IRST%20Account%20Brand%20Account%20Response%20IO");

    var updatedData = (IEnumerable<Account1>)dcs.ReadObject(stream);

    return updatedData;

XML - 数据已被清理,但对于本示例,它并不重要。

<ListOfIrstAccountBrandAccountResponseIo xmlns="http://www.siebel.com/xml/IRST%20Account%20Brand%20Account%20Response%20IO">
    <Account>
        <AccountStatus>Active</AccountStatus>
        <IRSTAccoutSectorNum>xxxxx</IRSTAccoutSectorNum>
        <MainFaxNumber>xxxxx</MainFaxNumber>
        <MainPhoneNumber>xxxxx</MainPhoneNumber>
        <Name>xxxxx</Name>
        <ParentAccountId></ParentAccountId>
        <ParentAccountName></ParentAccountName>
        <AccountRowId>xxxxx</AccountRowId>
        <ListOfCutAddress>
            <CutAddress>
                <City>xxxxx</City>
                <Country>xxxxx</Country>
                <County>xxxxx</County>
                <PostalCode>xxxxx</PostalCode>
                <PrimaryAddressFlg>x</PrimaryAddressFlg>
                <State>xx</State>
                <StreetAddress>xxxxx</StreetAddress>
                <StreetAddress2></StreetAddress2>
            </CutAddress>
        </ListOfCutAddress>
        <ListOfIrstBrandAccount>
            <IrstBrandAccount>
                <IRSTBrand>xxxxx</IRSTBrand>
                <IRSTBrandAccountNumber>xxxxx</IRSTBrandAccountNumber>
                <IRSTSIC>xx</IRSTSIC>
                <Name>xxxxx</Name>
            </IrstBrandAccount>
            <IrstBrandAccount>
                <IRSTBrand>xxxxx</IRSTBrand>
                <IRSTBrandAccountNumber>xxxxx</IRSTBrandAccountNumber>
                <IRSTSIC>xx</IRSTSIC>
                <Name>xxxxx</Name>
            </IrstBrandAccount>
            <IrstBrandAccount>
                <IRSTBrand>xxxxx</IRSTBrand>
                <IRSTBrandAccountNumber>xxxxx</IRSTBrandAccountNumber>
                <IRSTSIC>xx</IRSTSIC>
                <Name>xxxxx</Name>
            </IrstBrandAccount>
        </ListOfIrstBrandAccount>
        <ListOfInternalDivision>
            <InternalDivision>
                <Organization>xxxxx</Organization>
            </InternalDivision>
            <InternalDivision>
                <Organization>xxxxx</Organization>
            </InternalDivision>
        </ListOfInternalDivision>
        <ListOfServiceAgreement>
            <ServiceAgreement>
                <AccountId>xxxxx</AccountId>
                <AgreementId>xxxxx</AgreementId>
                <AgreementNumber>xxxxx</AgreementNumber>
                <AgreementStatus>xxxxx</AgreementStatus>
                <ListOfFsAgreementItem>
                    <FsAgreementItem>
                        <AgreementId>xxxxx</AgreementId>
                        <BPTier1>xx</BPTier1>
                        <BPTier2>xx</BPTier2>
                        <IRSTBuyingProgram>xxxxx</IRSTBuyingProgram>
                        <Product>xxxxx</Product>
                        <ProductId>xxxxx</ProductId>
                    </FsAgreementItem>
                    <FsAgreementItem>
                        <AgreementId>xxxxx</AgreementId>
                        <BPTier1>xx</BPTier1>
                        <BPTier2>xx</BPTier2>
                        <IRSTBuyingProgram>xxxxx</IRSTBuyingProgram>
                        <Product>xxxxx</Product>
                        <ProductId>xxxxx</ProductId>
                    </FsAgreementItem>
                    <FsAgreementItem>
                        <AgreementId>xxxxx</AgreementId>
                        <BPTier1>xx</BPTier1>
                        <BPTier2>xx</BPTier2>
                        <IRSTBuyingProgram>xxxxx</IRSTBuyingProgram>
                        <Product>xxxxx</Product>
                        <ProductId>xxxxx</ProductId>
                    </FsAgreementItem>
                    <FsAgreementItem>
                        <AgreementId>xxxxx</AgreementId>
                        <BPTier1>xx</BPTier1>
                        <BPTier2>xx</BPTier2>
                        <IRSTBuyingProgram>xxxxx</IRSTBuyingProgram>
                        <Product>xxxxx</Product>
                        <ProductId>xxxxx</ProductId>
                    </FsAgreementItem>
                    <FsAgreementItem>
                        <AgreementId>xxxxx</AgreementId>
                        <BPTier1>xx</BPTier1>
                        <BPTier2>xx</BPTier2>
                        <IRSTBuyingProgram>xxxxx</IRSTBuyingProgram>
                        <Product>xxxxx</Product>
                        <ProductId>xxxxx</ProductId>
                    </FsAgreementItem>
                </ListOfFsAgreementItem>
            </ServiceAgreement>
        </ListOfServiceAgreement>
    </Account>
</ListOfIrstAccountBrandAccountResponseIo>

wsdl - 我从文件中删除了端点 IP 地址。它不是公共服务,但调用该服务不是测试此场景所必需的。

<?xml version="1.0" encoding="UTF-8"?><definitions
 xmlns="http://schemas.xmlsoap.org/wsdl/"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:xsdLocal1="http://www.siebel.com/xml/IRST%20Account%20Address%20Query%20Request%20IO"
 targetNamespace="http://siebel.com/CustomUI"
 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:xsdLocal2="http://www.siebel.com/xml/IRST%20Account%20Brand%20Account%20Response%20IO"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:tns="http://siebel.com/CustomUI"
><types
><xsd:schema
 elementFormDefault="qualified"
 attributeFormDefault="unqualified"
 targetNamespace="http://www.siebel.com/xml/IRST%20Account%20Brand%20Account%20Response%20IO"
 xmlns:xsdLocal2="http://www.siebel.com/xml/IRST%20Account%20Brand%20Account%20Response%20IO"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
><xsd:annotation
><xsd:documentation
>Copyright (C) 2001-2004 Siebel Systems, Inc. All rights reserved. Siebel XSD Generation</xsd:documentation
></xsd:annotation
><xsd:element
 name="ListOfIrstAccountBrandAccountResponseIo"
 type="xsdLocal2:ListOfIrstAccountBrandAccountResponseIo"
></xsd:element
><xsd:complexType
 name="ListOfIrstAccountBrandAccountResponseIoTopElmt"
><xsd:sequence
><xsd:element
 name="ListOfIrstAccountBrandAccountResponseIo"
 maxOccurs="1"
 minOccurs="1"
 type="xsdLocal2:ListOfIrstAccountBrandAccountResponseIo"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="ListOfIrstAccountBrandAccountResponseIo"
><xsd:sequence
><xsd:element
 name="Account"
 maxOccurs="unbounded"
 minOccurs="0"
 type="xsdLocal2:Account"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="Account"
><xsd:sequence
><xsd:element
 name="Id"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="AccountStatus"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="IRSTAccoutSectorNum"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="MainFaxNumber"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="MainPhoneNumber"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="Name"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="ParentAccountId"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="ParentAccountName"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="AccountRowId"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="ListOfCutAddress"
 maxOccurs="1"
 minOccurs="0"
 type="xsdLocal2:ListOfCutAddress"
></xsd:element
><xsd:element
 name="ListOfIrstBrandAccount"
 maxOccurs="1"
 minOccurs="0"
 type="xsdLocal2:ListOfIrstBrandAccount"
></xsd:element
><xsd:element
 name="ListOfInternalDivision"
 maxOccurs="1"
 minOccurs="0"
 type="xsdLocal2:ListOfInternalDivision"
></xsd:element
><xsd:element
 name="ListOfServiceAgreement"
 maxOccurs="1"
 minOccurs="0"
 type="xsdLocal2:ListOfServiceAgreement"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="ListOfCutAddress"
><xsd:sequence
><xsd:element
 name="CutAddress"
 maxOccurs="unbounded"
 minOccurs="0"
 type="xsdLocal2:CutAddress"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="CutAddress"
><xsd:sequence
><xsd:element
 name="City"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="Country"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="County"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="PostalCode"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="PrimaryAddressFlg"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="State"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="StreetAddress"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="StreetAddress2"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="ListOfIrstBrandAccount"
><xsd:sequence
><xsd:element
 name="IrstBrandAccount"
 maxOccurs="unbounded"
 minOccurs="0"
 type="xsdLocal2:IrstBrandAccount"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="IrstBrandAccount"
><xsd:sequence
><xsd:element
 name="Id"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="IRSTBrand"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="IRSTBrandAccountNumber"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="IRSTSIC"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="Name"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="ListOfInternalDivision"
><xsd:sequence
><xsd:element
 name="InternalDivision"
 maxOccurs="unbounded"
 minOccurs="0"
 type="xsdLocal2:InternalDivision"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="InternalDivision"
><xsd:sequence
><xsd:element
 name="Organization"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="ListOfServiceAgreement"
><xsd:sequence
><xsd:element
 name="ServiceAgreement"
 maxOccurs="unbounded"
 minOccurs="0"
 type="xsdLocal2:ServiceAgreement"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="ServiceAgreement"
><xsd:sequence
><xsd:element
 name="AccountId"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="AgreementId"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="AgreementNumber"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="AgreementStatus"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="ListOfFsAgreementItem"
 maxOccurs="1"
 minOccurs="0"
 type="xsdLocal2:ListOfFsAgreementItem"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="ListOfFsAgreementItem"
><xsd:sequence
><xsd:element
 name="FsAgreementItem"
 maxOccurs="unbounded"
 minOccurs="0"
 type="xsdLocal2:FsAgreementItem"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="FsAgreementItem"
><xsd:sequence
><xsd:element
 name="Id"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="AgreementId"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="BPTier1"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="BPTier2"
 maxOccurs="1"
 minOccurs="1"
 type="xsd:string"
></xsd:element
><xsd:element
 name="IRSTBuyingProgram"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="Product"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
><xsd:element
 name="ProductId"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
></xsd:sequence
></xsd:complexType
></xsd:schema
><xsd:schema
 elementFormDefault="qualified"
 attributeFormDefault="unqualified"
 targetNamespace="http://siebel.com/CustomUI"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
><xsd:import
 namespace="http://www.siebel.com/xml/IRST%20Account%20Brand%20Account%20Response%20IO"
></xsd:import
><xsd:import
 namespace="http://www.siebel.com/xml/IRST%20Account%20Address%20Query%20Request%20IO"
></xsd:import
><xsd:element
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Input"
><xsd:complexType
><xsd:sequence
><xsd:element
 ref="xsdLocal1:ListOfIrstAccountAddressQueryRequestIo"
></xsd:element
></xsd:sequence
></xsd:complexType
></xsd:element
><xsd:element
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Output"
><xsd:complexType
><xsd:sequence
><xsd:element
 ref="xsdLocal2:ListOfIrstAccountBrandAccountResponseIo"
></xsd:element
><xsd:element
 name="Error_spcCode"
 type="xsd:string"
></xsd:element
><xsd:element
 name="Error_spcMessage"
 type="xsd:string"
></xsd:element
></xsd:sequence
></xsd:complexType
></xsd:element
></xsd:schema
><xsd:schema
 elementFormDefault="qualified"
 attributeFormDefault="unqualified"
 xmlns:xsdLocal1="http://www.siebel.com/xml/IRST%20Account%20Address%20Query%20Request%20IO"
 targetNamespace="http://www.siebel.com/xml/IRST%20Account%20Address%20Query%20Request%20IO"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
><xsd:annotation
><xsd:documentation
>Copyright (C) 2001-2004 Siebel Systems, Inc. All rights reserved. Siebel XSD Generation</xsd:documentation
></xsd:annotation
><xsd:element
 name="ListOfIrstAccountAddressQueryRequestIo"
 type="xsdLocal1:ListOfIrstAccountAddressQueryRequestIo"
></xsd:element
><xsd:complexType
 name="ListOfIrstAccountAddressQueryRequestIoTopElmt"
><xsd:sequence
><xsd:element
 name="ListOfIrstAccountAddressQueryRequestIo"
 maxOccurs="1"
 minOccurs="1"
 type="xsdLocal1:ListOfIrstAccountAddressQueryRequestIo"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="ListOfIrstAccountAddressQueryRequestIo"
><xsd:sequence
><xsd:element
 name="Account"
 maxOccurs="unbounded"
 minOccurs="0"
 type="xsdLocal1:Account"
></xsd:element
></xsd:sequence
></xsd:complexType
><xsd:complexType
 name="Account"
><xsd:sequence
><xsd:element
 name="AccountRowId"
 maxOccurs="1"
 minOccurs="0"
 type="xsd:string"
></xsd:element
></xsd:sequence
></xsd:complexType
></xsd:schema
></types
><message
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Input"
><part
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Input"
 element="tns:IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Input"
></part
></message
><message
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Output"
><part
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Output"
 element="tns:IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Output"
></part
></message
><portType
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
><operation
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
><input
 message="tns:IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Input"
></input
><output
 message="tns:IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version_Output"
></output
></operation
></portType
><binding
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
 type="tns:IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
><soap:binding
 transport="http://schemas.xmlsoap.org/soap/http"
 style="document"
></soap:binding
><operation
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
><soap:operation
 soapAction="document/http://siebel.com/CustomUI:IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
></soap:operation
><input
><soap:body
 use="literal"
></soap:body
></input
><output
><soap:body
 use="literal"
></soap:body
></output
></operation
></binding
><service
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
><port
 binding="tns:IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
 name="IRST_spcQuery_spcAccount_spcAnd_spcBrand_spcAccnt_Version"
><soap:address
 location="http://xx.xx.xx.xx/path/to/service"
></soap:address
></port
></service
></definitions
>
4

1 回答 1

0

看来我试图使用错误的序列化程序进行反序列化。3rd 方服务的 wsdl 的早期版本与DataContractSerializer. 他们实施的更改显然与我不兼容DataContractSerializersvcutil.exe切换到 using XmlSerializer,我不知道。

我切换到使用XmlSerializer反序列化,事情终于奏效了。

于 2012-12-02T23:05:04.937 回答