Re: Axis <-> .Net xsd:date interoperability problem

From: Dino Chiesa [Microsoft] (dinoch_at_online.microsoft.com)
Date: 07/28/04


Date: Wed, 28 Jul 2004 17:08:34 -0400

Sorry, I have misunderstood.

----
If you do not want to use this attribute, you can do some manual workaround.
.NET can de-serialize from alternative string representations of the date,
but you need to tell it the format to expect.  For example, in any class
that includes a System.DateTime that will be serialized and de-serialized
and must interop with a Java partner, you can add a shadow property, such as
:
  public class Wrapper {
    [XmlIgnore]
    public System.DateTime  actualBeginDate;
    public string beginDate{
      set {
        System.Globalization.CultureInfo CInfo= new
System.Globalization.CultureInfo("en-US", true);
         actualBeginDate= System.DateTime.ParseExact(value,
"yyyy-MM-ddTHH:mm:ss.fffZ", CInfo);
      }
      get {
         return actualBeginDate.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
      }
    }
  }
What this does is upon de-serialization, the beginDate is interpreted as a
string, and in the setter, you set the actual System.DateTime.  Upon
serialization, the reverse happens, and the actual DateTime is serialized in
a fashion that matches AXIS' format.  It is called a "shadow property"
because there is no actual member string.  Setting the string causes the
DateTime to be set.  Getting the string causes the DateTime to be formatted.
But I do not know how to do something similar as a global override for
serialization of all DateTime's.   I don't know if that is possible.
-Dino
"Jabb" <Jabb@discussions.microsoft.com> wrote in message
news:947DC439-9327-4F35-A51A-89A9EC294A60@microsoft.com...
> Dino, hi
> Thanx alot for your answer.
> As I understand, AXIS is able to read both lexical and canocical date
representation, while the .NET platform preferes the lexical one. My
question is could I do any system-scope definition (like registration of
default format/serializer etc) and not  an attributes adding (as you
suggest) to wsdl.exe generated code - say,  it is a considerable amount of
existing written code I wouldn't like to change?
> 10x ahead,
> Sincerely.
> Jabb.
>
> "Dino Chiesa [Microsoft]" wrote:
>
> > > I try to call the Axis-based service from the .Net client and faced an
> > interoperability problem for xsd:date type field.
> > > Has somebody had such a problem? What are possible solutions?
> >
> > yes
> >
> > see
> >
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlSerializationXmlElementAttributeClassDataTypeTopic.asp
> >
> > for doc on how to control the serialization of a Date.
> >
> > You want to decorate the DateTime field with
> > [XmlElement(DataType = "date")]
> >
> > which says "serialize this thing as an xsd:date.
> > There are other options, though. You can use "time" and "dateTime" as
well,
> > for the corresponding W3C XML Schema types.
> >
> > ----
> > The other issue you will run into is that in AXIS (and Java in general),
a
> > date can have a null value, while in .NET it cannot:  System.DateTime is
a
> > value type.   So you also need to handle the case where the date value
is
> > 'nil'.
> >
> > see http://blogs.msdn.com/smguest/archive/2004/05/07/128113.aspx for a
> > summary.
> >
> > You can do this with a xxxSpecified field, typed with [XmlIgnore].  This
is
> > automatically generated if you start from WSDL, and generate your client
> > classes from that.
> >
> > here's the doc
> >
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlSerializationXmlSerializerClassTopic.asp
> >
> > But be sure in your app code you check for XxxxSpecified before using
the
> > DateTime value.  The DateTime value in .NET is only meaningful if
> > XxxxSpecified is true, where Xxxx is the name of the property holding
the
> > DateTime.
> >
> > -Dino
> >
> > -- 
> > Dino Chiesa
> > Microsoft Developer Division
> > d i n o c h @  OmitThis . m i c r o s o f t . c o m
> >
> > ps: maybe now you will ditch those Sun forums and come to a usable forum
> > like the .NET newsgroups.
> >
> > ;)
> >
> >
> > "Jabb" <Jabb@discussions.microsoft.com> wrote in message
> > news:DC5BA1E6-E8FD-4210-A54C-3A75DA1B82F1@microsoft.com...
> > > Good evening <whatever else> to all.
> > > I'd like to repost to this forum message from Sun's JDC Forum :
> > http://forum.java.sun.com/thread.jsp?forum=34&thread=541653
> > > -----------------------------
> > > Hi, people
> > > I try to call the Axis-based service from the .Net client and faced an
> > interoperability problem for xsd:date type field. It looks different for
> > both platforms:
> > > in .Net->Axis request:
> > >
> > >   <beginDate>2004-07-27T18:07:32.5559555+03:00</beginDate>
> > >
> > > in Axis->.Net response:
> > >
> > >  <beginDate>2004-07-27T15:07:36.007Z<beginDate>
> > >
> > >
> > > As I see, Axis overcomes on the difference, but MS.NET - doesn't..
:( - I
> > receive an exception:
> > >
> > > Exception: System.InvalidOperationException: There is an error in XML
> > document (9, 86). --->
> > > System.FormatException: String was not recognized as a valid DateTime.
> > >   at System.DateTimeParse.ParseExactMultiple(String s, String[]
formats,
> > DateTimeFormatInfo dtfi, DateTimeStyles style, DateTime& result)
> > >   at System.DateTime.ParseExact(String s, String[] formats,
> > IFormatProvider provider, DateTimeStyles style)
> > >   at System.Xml.XmlConvert.ToDateTime(String s, String[] formats)
> > >   at System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String
value,
> > String[] formats)
> > >   at System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String
value)
> > >   at System.Xml.Serialization.XmlSerializationReader.ToDateTime(String
> > value)  .... etc
> > >
> > >
> > > Has somebody had such a problem? What are possible solutions?
> > > Thanx ahead, I'll very appreciate any inputs.
> > > Sincerely,
> > > Jabb.
> > > --------------------------
> > >
> > > Is the date serialization format a configuration issue of .Net
platform?
> > > Greatly appreciate any inputs
> > > Jabb.
> > >
> >
> >
> >


Relevant Pages

  • Re: dateTime Manupulations
    ... Notice the quoted string, a specific format for a date & time. ... will need to convert that string into a DateTime. ... > datetime conversion between strings, however it was a datetime conversion ...
    (microsoft.public.dotnet.languages.vb)
  • Re: convert a date to a string?
    ... converting it to a CHARACTER string. ... Also, don't convert it back to a datetime, or put it in a datetime variable, ... or you'll lose the format. ... >>> Declare @m int ...
    (microsoft.public.sqlserver.programming)
  • Re: Search an Outlook appointment
    ... Then I can make my search string using the strDate. ... And my problem is to convert datetime to a string: ... How can I get the right datetime format of the user for making the search? ... I need to search for Outlook appointements from date to date. ...
    (microsoft.public.win32.programmer.messaging)
  • RE: SqlCeEngine.CreateDataBase() - LCID - Datepart format problem
    ... Background info on why insert in your format doesn't work: ... datetime as string, SQL CE does an implicit convert from string to ... datetime formats with their style IDs are listed in CONVERT function in SQL ...
    (microsoft.public.sqlserver.ce)
  • Re: Dates
    ... The conversion of a char data type to a datetime data type resulted in an ... out-of-range datetime value. ... System.Data.Common.DbDataAdapter.FillFromReader(Object data, String ... srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) ...
    (microsoft.public.dotnet.framework.aspnet)