<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://bloggingabout.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'WCF', 'NHibernate', and 'DateTime'</title><link>http://bloggingabout.net/search/SearchResults.aspx?a=1&amp;o=DateDescending&amp;tag=WCF,NHibernate,DateTime&amp;orTags=0</link><description>Search results matching tags 'WCF', 'NHibernate', and 'DateTime'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>WCF and DateTime.Kind pitfall</title><link>http://bloggingabout.net/blogs/ramon/archive/2010/05/19/wcf-and-datetime-kind-pitfall.aspx</link><pubDate>Wed, 19 May 2010 08:48:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:483295</guid><dc:creator>Ramon Smits</dc:creator><description>&lt;p&gt;At my job (&lt;a href="http://www.companywebcast.com"&gt;Company Webcast&lt;/a&gt;) we have several API&amp;rsquo;s for our customers to use. One of those API&amp;rsquo;s allow webcasts to be created and modified and that interface has data containing dates. Our platform works with UTC date time&amp;rsquo;s as we are an international operating company so it is logical for use to store those as UTC.&lt;/p&gt;
&lt;p&gt;We use WCF and yesterday we had a very weird issue where calls failed. After investigating the issue we found out that the cause was that how the date time got supplied to our service in the message&lt;/p&gt;
&lt;p&gt;The following values are valid in an XML message:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;lt;ns1:ScheduledStart&amp;gt;2010-05-26T17:00:00+02:00&amp;lt;/ns1:ScheduledStart&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;ns1:ScheduledStart&amp;gt;2010-05-26T15:00:00Z&amp;lt;/ns1:ScheduledStart&amp;gt; &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A WCF service &lt;strong&gt;accepts both values but it treats them different&lt;/strong&gt; which I did not expect! The first value became 2010-05-26 17:00 where DateTime.Kind is set to Local and the second becomes 2010-05-26 15:00 with DateTime.Kind set to UTC. &lt;strong&gt;This amazed me a bit as I assumed that both would always result in either a UTC or Local DateTime&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The reason it fails is that another argument states the time-zone from where the live webcast will be held. This is used in combination with the DateTime to convert the DateTime value to a local time to inform the viewer about the conditions of the event. This code assumed that the incoming DateTime value would always be of kind UTC.&lt;/p&gt;
&lt;p&gt;So now our front-end api&amp;rsquo;s convert incoming DateTime values to a DateTime value with kind UTC.&lt;/p&gt;
&lt;p&gt;This could also be a problem when you persist this DateTime to for example a database and your storage logic does not convert the DateTime from/to UTC or Local depending on your needs. We use NHibernate for storage and it does not by default has a way to set UTC/Local to a &amp;lt;property&amp;gt; definition. This can really become a problem when time is part of your business logic as it is in ours as we use it to schedule tasks and it is very important to know it a time is UTC or not especially when something happens on the other side of the world.&lt;/p&gt;</description></item></channel></rss>