Why is my type not Serialized correctly XmlSerializer

The main problem was that when I called the webservice (asmx) method with the type, the type always passed as null. A Soap check confirmed that the type was empty. So I tried a simple test. Here is my type, which of course was created from WSDL

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://dto12.api.echosign")] public partial class SendDocumentInteractiveOptions { private bool authoringRequestedField; private bool authoringRequestedFieldSpecified; private bool autoLoginUserField; private bool autoLoginUserFieldSpecified; private bool noChromeField; private bool noChromeFieldSpecified; /// <remarks/> public bool authoringRequested { get { return this.authoringRequestedField; } set { this.authoringRequestedField = value; } } /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool authoringRequestedSpecified { get { return this.authoringRequestedFieldSpecified; } set { this.authoringRequestedFieldSpecified = value; } } /// <remarks/> public bool autoLoginUser { get { return this.autoLoginUserField; } set { this.autoLoginUserField = value; } } /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool autoLoginUserSpecified { get { return this.autoLoginUserFieldSpecified; } set { this.autoLoginUserFieldSpecified = value; } } /// <remarks/> public bool noChrome { get { return this.noChromeField; } set { this.noChromeField = value; } } /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool noChromeSpecified { get { return this.noChromeFieldSpecified; } set { this.noChromeFieldSpecified = value; } } } 

Now here is some simple code to serialize it.

 SendDocumentInteractiveOptions sdio = new SendDocumentInteractiveOptions(); sdio.authoringRequested = true; sdio.autoLoginUser = true; sdio.noChrome = true; XmlSerializer xmlSer = new XmlSerializer(typeof(SendDocumentInteractiveOptions)); XmlWriter xw = new XmlTextWriter(@"g:\test.xml", null); xmlSer.Serialize(xw, sdio); xw.Close(); 

And here is the resulting XML

& lt; xml version = "1.0" & gt; & ltSendDocumentInteractiveOptions xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" / & gt

So what I am missing here. Why aren't my public properties getting serialized?

0
xml-serialization
Mar 19 '12 at 19:28
source share
1 answer

This is an old question, but good. I think the solution may be in another question "Why is my public property not serialized by XmlSerializer?" . The answers section lists the reasons why the attribute will not be serialized, and in this list

  • it has the public property bool FooSpecified {get; set;}, which returns false

In your code, you set various boolean values, but set the appropriate given values. I ran into a similar problem and set the specified value for me.

+1
Jan 16 '13 at 18:53
source share



All Articles