c# - WCF With XmlSerializer -


i have xml string

<?xml version="1.0"?> <fullserviceaddresscorrectiondelivery xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema">   <authenticationinfo  xmlns="http://www.usps.com/postalone/services/userauthenticationschema">     <userid xmlns="">fapushservice</userid>     <userpassword xmlns="">password4now</userpassword>   </authenticationinfo>   <fullserviceaddresscorrectiondelivery d2p1:messagegroupid="3599" d2p1:totalmessagecount="1" d2p1:messageserialnumber="1" xmlns:d2p1="http://idealliance.org/specs/mailxml10.0/mailxml_defs" xmlns="http://idealliance.org/specs/mailxml10.0a/mailxml_dd">     <submittingparty d2p1:maildatuserlicense="usps" />     <submittingsoftware d2p1:softwarename="postalone" d2p1:vendor="usps" d2p1:version="27.0" />     <pushmessageid>3599001</pushmessageid>   </fullserviceaddresscorrectiondelivery> </fullserviceaddresscorrectiondelivery> 

and service contract like

[servicecontract(namespace = http://www.usps.com/postalone/services/datadistributionpushmailxml10a")] public interface datadistributionpushmailxml10aporttype {     [operationcontract]     [xmlserializerformat]     fullserviceaddresscorrectiondelivery pushfullserviceaddresscorrectiondelivery(fullserviceaddresscorrectiondelivery obj); }  // use data contract illustrated in sample below add composite types service operations. [datacontract(name = "fullserviceaddresscorrectiondelivery", namespace = "http://www.w3.org/2001/xmlschema-instance")] [serializable] public class fullserviceaddresscorrectiondelivery {     [xmlelement("authenticationinfo",       namespace = "http://www.usps.com/postalone/services/userauthenticationschema")]     [datamember]     public authenticationinfotype authenticationinfo     {         get;         set;     }      [xmlelement("fullserviceaddresscorrectiondelivery",      namespace = "http://idealliance.org/specs/mailxml10.0a/mailxml_dd")]     [datamember]     public fullserviceaddresscorrectiondelivery1 fullserviceaddresscorrectiondelivery1     {         get;         set;     } }  [datacontract] [serializable] public class authenticationinfotype {     [datamember]     [xmlelement("userid", namespace = "")]     public string userid     {         get;         set;     }      [datamember]     [xmlelement("userpassword", namespace = "")]      public string userpassword     {         get;         set;     } }  [datacontract] [serializable] public class participantidtype {     private string _maildatuserlicense;      [datamember]     [xmlattribute("maildatuserlicense",      namespace ="http://idealliance.org/specs/mailxml10.0/mailxml_defs")]      public string maildatuserlicense     {                 {             return this._maildatuserlicense;         }         set         {             this._maildatuserlicense = value;         }     } }  [datacontract] [serializable] public class fullserviceaddresscorrectiondelivery1 {     [datamember]     [xmlelement("submittingparty")]     public participantidtype submittingparty     {         get;         set;     }      [datamember]     [xmlelement("pushmessageid")]     public string pushmessageid     {         get;         set;      } } 

on deserializing, use xmlserializer:

fullserviceaddresscorrectiondelivery objaddresscorrectiondelivery =    new  fullserviceaddresscorrectiondelivery(); byte[] bytearray = system.text.encoding.ascii.getbytes(this.richtextbox1.text); memorystream stream = new memorystream(bytearray); xmlserializer xs = new xmlserializer(typeof(fullserviceaddresscorrectiondelivery)); var result = (fullserviceaddresscorrectiondelivery)xs.deserialize(stream); 

problem while deserializing: fullserviceaddresscorrectiondelivery object deserialized, contains null in pushmessageid property. have missed?

the reason fullserviceaddresscorrectiondelivery1 class (the inner fullserviceaddresscorrectiondelivery) doesn't contain definition of submittingsoftware element, xml contains it. seems happen xml deserializer can read properties before submittingsoftware, properties after submittingsoftware set null. have experienced myself in deserializing xml web services.

typically happen if create client using version 1 of web service , create version 2 of web service, having 1 more property in datacontract. in cases, need ensure new property placed last (at bottom) in xml.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -