none
WCF client request loses DateTime elements RRS feed

  • Question

  • I have WCF client that has created an proxy to a JAVA web service. I am able to contact this service and I am as well able to retrieve data from it. However some of the fields, to be exact C# DateTime fields, that I define within the request get lost just before I send them.

    Through the diagnostics settings I was able to log this behavior and could see the following before the message was sent:


    <SOAP-ENV:Body>
       <HentFeriepengeinfoAnmodningsListe xmlns="http://tempuri.org/">
         <UdbetalerSEnummerIdentifikator>xxxxxxxx</UdbetalerSEnummerIdentifikator>
         <FerieaarIdentifikator>2015</FerieaarIdentifikator>
         <ArbejdsgiverSEnummerIdentifikator xmlns="" xsi:nil="true"/>
         <CPRnummerIdentifikator xmlns="" xsi:nil="true"/>
         <MedarbejderNummerIdentifikator xmlns="" xsi:nil="true"/>
         <AnmodningFraDato>2015-03-25T00:00:00.000+01:00</AnmodningFraDato>
         <AnmodningTilDato>2015-03-24T00:00:00.000+01:00</AnmodningTilDato>
         <FoersteFeriedagFraDato>2015-05-01T00:00:00.000+01:00</FoersteFeriedagFraDato>
         <FoersteFeriedagTilDato>2016-04-30T00:00:00.000+01:00</FoersteFeriedagTilDato>
         <AnmodningNummerIdentifikator xmlns="" xsi:nil="true"/> <InklusivAfvisteIndikator>false</InklusivAfvisteIndikator>
       </HentFeriepengeinfoAnmodningsListe>
    </SOAP-ENV:Body>

    What should be noted here are the elements that contains DateTime values. And this is what follows:

    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <HentFeriepengeinfoAnmodningsListe xmlns="urn:oio:atp:feriepengeinfo:anmodninger:1.0.0">
         <UdbetalerSEnummerIdentifikator xmlns="urn:oio:atp:1.0.0">xxxxxxxx</UdbetalerSEnummerIdentifikator>
         <FerieaarIdentifikator>2015</FerieaarIdentifikator>
         <InklusivAfvisteIndikator>false</InklusivAfvisteIndikator>
       </HentFeriepengeinfoAnmodningsListe>
    </s:Body>

    Now the DateTime elements have been removed.

    This is the XSD that where used to define one of the vanished elements

    <?xml version="1.0" encoding="utf-8"?>
    <xsd:schema xmlns:atp="urn:oio:atp:1.0.0" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:oio:atp:1.0.0" xml:lang="DA" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="AnmodningFraDato" type="xsd:date" />
    </xsd:schema>

    And this is the part of the code that got generated through WCF, based on the WSDL supplied by the JAVA service.

    [System.Xml.Serialization.XmlElementAttribute(Namespace="urn:oio:atp:1.0.0", DataType="date", Order=5)]
    [System.Runtime.Serialization.DataMember]
    public System.DateTime AnmodningFraDato {
       get {
           return this.anmodningFraDatoField;
       }
       set {
           this.anmodningFraDatoField = value;
           this.RaisePropertyChanged("AnmodningFraDato");
       }
    }

    You might notice that the datatype is defined as "date", but since the only approximation C# offers is the DateTime type I would not know what else to use here.

    If anyone could shed some light on whats happening here I would really appreciate it.



    • Edited by Søren-ssv Tuesday, March 24, 2015 10:50 PM
    Tuesday, March 24, 2015 10:47 PM

Answers

  • Hello Søren-ssv,

    You could try passing DateTime as a long value in milliseconds.

    In C# you could do something like this

    private static readonly DateTime Jan1st1970 = new DateTime

        (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

    public static long CurrentTimeMillis()

    {

        return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;

    }

    And then in Java convert the milliseconds to date

    You may use java.util.Date class and then use SimpleDateFormat to format the Date.

    Date date=new Date(millis);

    Hope this helps you.

    With Regards,

    Shawn
    Friday, April 3, 2015 9:51 AM
    Moderator

All replies

  • Java does not have the datatime type.
    You can convert the DateTime in C# to string, then convert this string to Date in Java Web Services.
    Thursday, March 26, 2015 10:18 AM
  • Hello Søren-ssv,

    You could try passing DateTime as a long value in milliseconds.

    In C# you could do something like this

    private static readonly DateTime Jan1st1970 = new DateTime

        (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

    public static long CurrentTimeMillis()

    {

        return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;

    }

    And then in Java convert the milliseconds to date

    You may use java.util.Date class and then use SimpleDateFormat to format the Date.

    Date date=new Date(millis);

    Hope this helps you.

    With Regards,

    Shawn
    Friday, April 3, 2015 9:51 AM
    Moderator