Based on the ideas Dino sent me, I managed to find out a working solution to my
problem. I also realised that it's possible to keep xsd:dateTime in my schema and to
use it in a Web Service. Only drawback is that the wsdl can't be autogenerated.
Here's roughly what I came up with:
public class Approval {
public string Manager;
public int ProjectId;
public string Location;
public string ApprovedAt;
[XmlIgnore]
public DateTime LocalApprovedAt {
get {
return DateTime.Parse(ApprovedAt);
}
set {
ApprovedAt = value.ToString("yyyy-MM-ddTHH:mm:ss");
}
}
}
public static void TestApproval() {
Approval obj = new Approval();
obj.Manager = "Smith";
obj.ProjectId = 1234;
obj.Location = "Pleasantville";
obj.LocalApprovedAt = DateTime.Parse("2002-02-28 13:48:00");
XmlSerializer serializer = new XmlSerializer(typeof(Approval));
StreamWriter writer = new StreamWriter("obj.xml");
serializer.Serialize(writer, obj);
writer.Close();
}
/Bjorn
[quoted text, click to view] "Dino Chiesa [Microsoft]" wrote:
> This example shows some of the possibilities.
>
http://www.winisp.net/cheeso/srcview.aspx?dir=xml-serialization&file=DateTime.cs >
> -D
>
> "BjörnHolmberg" <bjRemovethiSorn.holmberg@suliteAndthiSlma.com> wrote in
> message news:411345C6.4AFD1A22@suliteAndthiSlma.com...
> > Hi everyone!
> >
> > In the following code we get a UTC offset in xml. Since I want my WAP
> users in
> > UTC+02:00 to see data on a server in some US time zone, a lot of confusion
> will
> > be created from this behavior. Either I use .NET logic on the server and
> get
> > server local time or I create xhtml pages directly from serialized
> objects.
> > Eitherway I'll have to write my own logic to take care of utc offset. Is
> it
> > possible to override XmlSerializer so what my local desktop user send to
> the
> > webservice is saved on the server without utc offset? That way, the time
> that is
> >
> > local to my users will be saved on the server. I guess it's kind of hard
> to
> > tweak ASP.NET WebService infrastructure into this. On the other hand it
> feels
> > like bad manners to change my xsd:dateTime values to xsd:string because of
> what
> > i discover about .NET. /Regards Bjorn
> >
> > public class SomeDates {
> > public DateTime Summer;
> > public DateTime Winter;
> > }
> >
> > public static void TestSomeDates() {
> > SomeDates obj = new SomeDates();
> > obj.Winter = DateTime.Parse("2003-12-22 12:32:45");
> > obj.Summer = DateTime.Parse("2004-08-05 18:45:21");
> > XmlSerializer serializer = new XmlSerializer(typeof(SomeDates));
> > StreamWriter writer = new StreamWriter("obj.xml");
> > serializer.Serialize(writer, obj);
> > writer.Close();
> > }
> >
> >
> >
> >
> >