2012-11-16 84 views
0

我在將一些XML反序列化爲適當的對象結構時遇到了問題。當我在我的DataContractSerializer上撥打ReadObject(stream)時,它將返回一個空數組。沒有錯誤,不爲空,只是一個空數組。DataContractSerializer ReadObject(流)返回空值

我使用第三方服務,他們提供了一個WSDL的故事。我已將wsdl作爲服務參考添加到我的項目中。我已經成功地調用了此服務並收到了一個響應,該響應由.Net正確反序列化。所以我知道響應能夠被反序列化。

我打電話給服務一次以獲得一些初始數據。然後,當第三方更新數據時,他們將使用服務返回的相同響應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 
> 

回答

0

看來我試圖使用錯誤的序列化程序進行反序列化。以前版本的第三方服務的wsdl與DataContractSerializer一起工作正常。他們實施的更改顯然與DataContractSerializersvcutil.exe切換爲使用XmlSerializer不兼容,我不知道。

我改用XmlSerializer進行反序列化,事情終於奏效。