I use WebClient class to send a response acknowledge message in an mvc 3 project. Message is sending from one action method on a project to another projects action method.
Surprisingly the date parameter is 3 hours later, on recieving data.
For example if my sending date is receving data is “2012-08-14 13:42:50Z” i see “2012-08-14 16:42:50Z” on the other side.
Here is a simplified code sample of my case;
NameValueCollection ack = new NameValueCollection();
ack.Add("RESID", form.RESPONSE.ID.ToString());
ack.Add("A_DateTime", DateTime.Now.ToString("u")); //2012-08-14 13:42:50Z
using (var client = new WebClient())
{
client.Encoding = System.Text.Encoding.UTF8;
var result = client.UploadValues("http://localhost:11578/HPM/ResponseAck", ack);
}
//HPM Controller:
ResponseAck(HttpPostResponseAckMessage response)
{
//Here response.Date vale is 2012-08-14 16:42:50Z ???
}
It seems to me its about sneaky little serialization monsters changing it cause of some culture specific issue. But i don’t know the real cause so the solution.
Edit:
public class HttpPostResponseAckMessage
{
public int RESID { get; set; }
public DateTime A_DateTime { get; set; }
}
Ok, I think its about expecting mvc model binder to parse a formated datetime.
With the “u” format model binder thinks the datetime is UTC.
So my solution will be changing the type of property A_DateTime to string and will parsing it internaly.
Hope this helps someone else like me.
Thanks all.