Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom DateTime XML Serialization
    primarykey
    data
    text
    <p>I would like to be able to Serialize a DateTime with a specific Time Zone that is not the server, nor is it client time. Basically, any time zone. Is it possible to override the DateTime serialization, in .Net2.0 webservices?</p> <p>I compile an xmlschema using xsd.exe, so I made an attempt using XmlSchemaImporter.</p> <p>The OnSerialize examples show value changes, but not changes to the output format.</p> <p>XmlSchemaImporter, loaded it into the gac, ran xsd.exe, and generated code that has the class I want... but that class is an attribute, which end up not being able to be reflected.</p> <blockquote> <p>[InvalidOperationException: Cannot serialize member 'metadataDateTime' of type Cuahsi.XmlOverrides.W3CDateTime. XmlAttribute/XmlText cannot be used to encode complex types.]</p> </blockquote> <p>Generated code</p> <pre><code>[System.Xml.Serialization.XmlAttributeAttribute()] public Cuahsi.XmlOverrides.W3CDateTime dateTime { get { return this.dateTimeField; } set { this.dateTimeField = value; } } </code></pre> <p>XmlSchemaImporter</p> <pre><code>public class ImportW3CTime : System.Xml.Serialization.Advanced.SchemaImporterExtension { public override string ImportSchemaType(string name, string ns, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) { if (XmlSchema.Namespace == ns) { switch (name) { case "dateTime": string codeTypeName = typeof(W3CDateTime).FullName; CodeTypeDeclaration cls = new CodeTypeDeclaration("W3CDateTime"); cls.IsStruct = true; cls.Attributes = MemberAttributes.Public; cls.BaseTypes.Add("dateTime"); mainNamespace.Types.Add(cls); return codeTypeName; default: return null; } } else { return null; } } } </code></pre> <p><strong>Addendum 1:</strong> I just tired DateTimeoffset, and that still causes an error when the class is tagged like:</p> <pre><code>[System.Xml.Serialization.XmlAttributeAttribute(DataType = "dateTime")] public System.DateTimeOffset metadataDateTime { get { return this.metadataDateTimeField; } set { this.metadataDateTimeField = value; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload