Reputation: 1
I am experiencing a very strange behavoiour of Flex Date object. My web service is written in .Net 3.5 and all object which I am retriving or updating have Creation Date (Date Type) in .Net code.
But when I am calling .Net web service and displaying data in Flex, Flex displaying a different Date than what stored in web service. When I update my object using Flex UI, every time update time is very different than actual update time set by .Net code.
Can any one help me solve this ?
Upvotes: 0
Views: 6306
Reputation: 1113
Flex app.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
private function init():void
{
updateFlexTime();
}
private function updateFlexTime():void
{
flexTimeLabel.text = new Date().toString();
flexLocalTimeLabel.text = new Date().toLocaleString();
}
private function refreshHandler(event:Event):void
{
dateTimeService.GetCurrentDateTimeAsString();
}
private function onGetCurrentDateTimeAsString(event:ResultEvent):void
{
var value:String = String(event.result);
var currentDate:Date = new Date(Date.parse(value));
remoteTimeLabel.text = currentDate.toString();
remoteLocalTimeLabel.text = currentDate.toLocaleString();
updateFlexTime();
}
]]>
</mx:Script>
<mx:Form>
<mx:FormItem label="Flex time:">
<mx:Text id="flexTimeLabel"/>
</mx:FormItem>
<mx:FormItem label="Remote time:">
<mx:Text id="remoteTimeLabel"
text="Press refresh button."/>
</mx:FormItem>
<mx:FormItem label="Flex local time:">
<mx:Text id="flexLocalTimeLabel"/>
</mx:FormItem>
<mx:FormItem label="Remote local time:">
<mx:Text id="remoteLocalTimeLabel"
text="Press refresh button."/>
</mx:FormItem>
<mx:Button label="Refresh"
click="refreshHandler(event)"/>
</mx:Form>
<mx:WebService id="dateTimeService"
endpointURI="http://localhost:2054/TestService.asmx"
wsdl="http://localhost:2054/TestService.asmx?wsdl">
<mx:operation name="GetCurrentDateTimeAsString"
resultFormat="object"
result="onGetCurrentDateTimeAsString(event)"/>
</mx:WebService>
.Net WebService:
namespace Lab.StackOverflow
{
using System;
using System.Web.Services;
/// <summary>
/// Test date/time service
/// </summary>
[WebService(Namespace = "http://lab.stackoverflow.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class TestService : WebService
{
/// <summary>
/// Get current date and time
/// </summary>
/// <returns>
/// Return UTC date time by RFC 1123 standard.
/// </returns>
[WebMethod]
public string GetCurrentDateTimeAsString()
{
return string.Format("{0:r}{1:zz}", DateTime.Now, DateTime.Now);
}
}
}
Upvotes: 0
Reputation: 6872
Your date issues may be a result of how timezones and serialization are handled between Flex and your server. I've had problems with Flex dates and Java so I will explain somethings encountered there:
Upvotes: 3
Reputation: 1115
I don't have an immediate answer, but some of the factors to consider are:
Is the date ambiguous? You didn't supply a sample of what the return might be, but a date like 09/10/2009 is ambiguous unless both ends agree on the format (dd/mm/yyyy or mm/dd/yyy).
Flex is basically a form of ECMAScript and a format from IETF RFC 1123 Section 5.2.14 should parse correctly. For example:
Mon, 28 Sep 2009 21:22:00 GMT
The Date object in .NET should be able to produce that (I can't remember off the top of my head) and the Date object in Flex should be able to parse it.
Upvotes: 0