<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nate Beck &#187; SOAP</title>
	<atom:link href="http://blog.natebeck.net/tag/soap/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.natebeck.net</link>
	<description>AIR, Flex / Flash, FMS, PushButton, Game... Developer</description>
	<lastBuildDate>Wed, 07 Sep 2011 21:24:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Flex, DateTimes, .NET&#8230;.. Why can&#8217;t we all just get along?</title>
		<link>http://blog.natebeck.net/2008/12/flex-datetimes-net-why-cant-we-all-get-along/</link>
		<comments>http://blog.natebeck.net/2008/12/flex-datetimes-net-why-cant-we-all-get-along/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 22:37:27 +0000</pubDate>
		<dc:creator>Nate Beck</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[SOAP]]></category>

		<guid isPermaLink="false">http://blog.natebeck.net/?p=5</guid>
		<description><![CDATA[Recently I've been working on a project that has a very interesting architecture. It's a scheduling application that has a Flex front end, C# .NET Middle tier, nHibernate DAL and Oracle database.  We're using SOAP to transfer data back and forth to the Flex client.

So there I was, writing a dashboard which polls to see if the data has been updated.  The idea is to request data from the server, store the servers timestamp on the client, and then check for updates by sending the time stamp back to the server.]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been working on a project that has a veryÂ interestingÂ architecture. It&#8217;s a scheduling application that has a Flex front end, C# .NET Middle tier, nHibernate DAL and Oracle database. Â We&#8217;re using SOAP to transfer data back and forth to the Flex client&#8230;..</p>
<p>[Rant]</p>
<p>I&#8217;m well aware of the other options that this client could have used to pass data back and forth. Frankly, I would have been much happier with anything other than SOAP. Â But alas, this is the decision the client made before I was on the project.Â </p>
<p>&lt;3 AMF</p>
<p>[/Rant]Â </p>
<p>&#8230;.. so there I was, writing a dashboard which polls to see if the data has been updated.  The idea is to request data from the server, store the servers timestamp on the client, and then check for updates by sending the timestamp back to the server.</p>
<p>Using C#, the web method is very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>WebMethod<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> StatusResponse IsUpdated<span style="color: #008000;">&#40;</span>DateTime timestamp<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	StatusResponse response<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Query or do what you gotta to give a valid response based on timestamp</span>
&nbsp;
	response <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StatusResponse<span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Now</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">return</span> response<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>In Flex I set up a test application which allows me to send requests to the server. I should mention, the client and the server are running on the same machine, which is why I am comparing local client time to server time.  This is my result handler</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> onStatusResponse<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	_lastTimestamp = event.<span style="color: #006600;">result</span>.<span style="color: #006600;">Timestamp</span> as <span style="color: #0066CC;">Date</span>;
	<span style="color: #000000; font-weight: bold;">var</span> now:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> diff:<span style="color: #0066CC;">int</span> = now.<span style="color: #0066CC;">time</span> - _lastTimestamp.<span style="color: #0066CC;">time</span>;
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ClientTime: &quot;</span>+now<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ServerTime: &quot;</span>+event.<span style="color: #006600;">result</span>.<span style="color: #006600;">Timestamp</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Difference (ms): '</span>+diff<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>As I&#8217;m watching my data being outputted, I was a little disturbed with the results.</p>
<p>&#8211; Requesting Server Time &#8211;<br />
ClientTime: Sat Dec 6 09:09:05 GMT-0800 2008<br />
ServerTime: Sat Dec 6 09:23:32 GMT-0800 2008<br />
Difference (ms): -866850<br />
&#8211; Requesting Server Time &#8211;<br />
ClientTime: Sat Dec 6 09:09:25 GMT-0800 2008<br />
ServerTime: Sat Dec 6 09:32:00 GMT-0800 2008<br />
Difference (ms): -1355072<br />
&#8211; Requesting Server Time &#8211;<br />
ClientTime: Sat Dec 6 09:09:25 GMT-0800 2008<br />
ServerTime: Sat Dec 6 09:10:02 GMT-0800 2008<br />
Difference (ms): -37070</p>
<p>You&#8217;ll notice that the ServerTime is getting pushed forward by some random amount of time.  This is a big problem! If I am polling for updates every 30 seconds, and the last timestamp I received was 10 minutes in the future, the query will always return a status of false.</p>
<p>So what&#8217;s going on here?  Why does Flex think that my Date is actually in the future when it&#8217;s retrieved from the web services?</p>
<p>Naturally, I started by looking at the web service response:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
2008-12-06T08:49:02.2292832-08:00
false</pre></div></div>

<p>A status of false simply means that the data has not been updated. Let&#8217;s look closely at the timestamp.</p>
<p>2008-12-06T08:49:02.2292832-08:00</p>
<p>According to the <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">w3.org xml schema</a>, everything looks good with that string.  But one thing catches my eye: &#8216;.&#8217; s+ (if present) represents the fractional seconds.</p>
<p>With a bit of research, I quickly learned there is a big difference between milliseconds (0-999) and fractional seconds.  The schema doesn&#8217;t dictate what precision the milliseconds need to be in.  So the C# webservice is using a precision of up to 7 digits.  This seemed highly suspect to me, but the string is technically correct.</p>
<p>So now I needed to dive into Flex, and figure out where the data was being corrupted.</p>
<p>** fast forward a week **</p>
<p>After quite a bit of investigating, I figured it out.</p>
<p>frameworks/projects/rpc/src/mx/rpc/xml/SchemaMarshaller.as</p>
<p>Within the SchemaMarshaller, the milliseconds are being treated as just that&#8230; milliseconds.  So when C# returned fractional seconds with a precision of 7 places (2292832), the marshaller was simply just appending 2,292,832 milliseconds to my date.</p>
<p>I submitted a patch which solved the issue, and while I was writing this post, I noticed that the fix has already been committed into the the Flex 4 repository.</p>
<p>Thanks Adobe, you guys rock!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.natebeck.net/2008/12/flex-datetimes-net-why-cant-we-all-get-along/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

