0

Variations of this question have been asked apparently dozens of times, but the solution that I need seems to be extremely elusive. I'm hoping that this time is the charm!

I have a C# application which is communicating with a Java web service via SOAP xml. The application has imported the service using the WSDL without a problem. However, one of xml objects is of type dateTime.

<complexType name="Interaction">
    <sequence>
        <element name="ContactDate" type="dateTime" minOccurs="0" maxOccurs="1"/>
    </sequence>
</complexType>

I have a date which I've retrieved from a database, which looks like this: 2013-07-10. I need to get it into the XML dateTime object using the UTC format: yyyy-MM-ddTHH:mm:ss.fffzzz

I can easily convert this to a properly parsed string. That's not the problem. The issue occurs when I try to load the data into the service object. I can't load the data as a string. It HAS to be a DateTime object, but DateTime refuses to use the UTC format.

I thought this might be a problem with serialization. I think it's failing to serialize properly when converting to xml to be sent to the web service. Here's the serialization information for this particular element:

[System.Xml.Serialization.XmlElementAttribute(Order=2)]
public System.DateTime ContactDate {
    get {
        return this.contactDateField;
    }
    set {
        this.contactDateField = value;
        this.RaisePropertyChanged("ContactDate");
    }
}

Any ideas on what I might be missing or doing wrong? Any help would be greatly appreciated. Thanks!

  • 2
    Is this a serialization problem, or a parsing problem? Is this answer helpful? http://stackoverflow.com/a/1756681/116895 – lance Jul 12 '13 at 15:24
  • 1
    Another potential help? http://stackoverflow.com/q/6314154/116895 – lance Jul 12 '13 at 15:36
  • Still researching this, but both of these tips provided seem to be for the common scenario of taking xml or a DateTime and converting it to a string. Converting to string doesn't appear to be the issue. It's more about forcing the DateTime to serialize into the proper format. It'd be nice if I could capture the serialized output to verify what it was putting in there. – David Levins Jul 15 '13 at 20:21
  • 1
    I think I understand why my answer isn't what you are looking for, but I'm having a hard time understanding where this breaks down. You get a `System.DateTime` from the database and you put it into the `ContactDate` property and the you serialize everything and what do you get? Do you get your local timezone offset or something else? – Jeff Walker Jul 16 '13 at 15:22
  • I'm almost completely certain it's a serialization problem now. I've attempted to set the ContactDate as both a DateTime object and as a String (after changing the Reference stuff to string instead of System.DateTime). The person managing the web services on the other end reports, in both cases, the value being received is null. So I'm setting a value, but it's not getting to the destination. – David Levins Jul 16 '13 at 19:47

2 Answers2

0

You use Z to indicate UTC. Is this your problem?

You can read more about it here: http://www.w3.org/TR/xmlschema-2/#dateTime-timezones

So, 2002-10-10T07:00:00Z is 10 October 2002 at 0700 UTC.

Jeff Walker
  • 1,656
  • 1
  • 18
  • 36
0

In the end, this was the very unfortunate answer that we came up with for this issue. We weren't able to identify anyway to force C# to properly serialize into the datetime format. To get around it, we eventually changed the WSDL for the Java web services to change the type to string. Once it was set to string, everything else was obviously easy.

complexType name="Interaction">
    <sequence>
        <element name="ContactDate" type="string" minOccurs="0" maxOccurs="1"/>
    </sequence>
</complexType>