I’m having trouble deserializing some XML into it’s appropriate object structure. When I call ReadObject(stream) on my DataContractSerializer it returns an empty array. No errors, not null, just an empty array.
The Story
I’m using a 3rd-party service and they have provided a wsdl. I have added the wsdl as a Service Reference to my project. I’ve successfully called out to this service and received a response, which is properly deserialized by .Net. So I know the response is capable of being deserialized.
I call out to the service once to get some initial data. Then, when the 3rd-party updates that data, they are going to POST to an MVC URL using the same response XML returned by the service. When I try to deserialize the XML from Request.InputStream I get an empty array.
I’ve searched and searched, but apparently not in the right places as I’ve come up totally blank.
I’d really appreciate any direction you can provide.
Here are the code and files in play:
My Deserialization Code – pretty straightforward stuff, no? updatedData is the null array in question.
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;
The XML – The data has been sanitized, but for this example it’s not important.
<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>
The wsdl – I removed the endpoint IP address from the file. It’s not a public service, but calling the service isn’t necessary for testing this scenario.
<?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
>
It appears that I was trying to deserialize using the wrong serializer. Previous editions of the 3rd party service’s wsdl was working fine with
DataContractSerializer. Changes they implemented are apparently incompatible withDataContractSerializerandsvcutil.exeswitched to usingXmlSerializer, unbeknownst to me.I switched to using
XmlSerializerfor deserialization and things are finally working.