Web Api 2 DatetimeOffset XML Serialization Issue
<p>Below is the property in my model:</p>
<pre><code> public DateTimeOffset AcquireDate { get; set; }
</code></pre>
<p>Below is the configuration in WebApiConfig:</p>
<pre><code>config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
config.Formatters.Add(new XmlMediaTypeFormatter()); 
</code></pre>
<p>Below is the json response (date is in IS 8601 format):</p>
<p><a href="https://i.stack.imgur.com/kA792.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kA792.png" alt="enter image description here" /></a></p>
<p>Below is the XML response:</p>
<pre><code>&lt;AcquireDate xmlns:d3p1=&quot;http://schemas.datacontract.org/2004/07/System&quot;&gt;
      &lt;d3p1:DateTime&gt;2008-01-10T16:40:12.1523923Z&lt;/d3p1:DateTime&gt;
      &lt;d3p1:OffsetMinutes&gt;330&lt;/d3p1:OffsetMinutes&gt;
&lt;/AcquireDate&gt;
</code></pre>
<p>From fiddler:</p>
<p><a href="https://i.stack.imgur.com/5Qkrx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Qkrx.png" alt="enter image description here" /></a></p>
<p>In Xml response, datetime and offset are available in two different elements. I want DateTimeOffset as single value, just like json response (in ISO 8601 format).</p>
<p>I could use one more property which would be of type string and that way my problem could be solved (empty setter requires for this property to be serialized).</p>
<pre><code>[DataMember(Name=&quot;AcquireDate&quot;)]
    public string AcquireDateString
    {
        get
        {
            return AcquireDate.ToString(&quot;yyyy-MM-ddTHH:mm:ss.fffffffzzz&quot;);
        }
        set {
            AcquireDate = DateTimeOffset.Parse(value); 
        }
    }
</code></pre>
<p>Any other solution apart from that?</p>
<p><strong>Solution should not affect existing Json Serialization which is working fine.</strong></p>