Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to upload data to SAP via a webservice, using WCF in c# 4.0 (VS2010). I have been able to connect and post data to the using the webservice successfully, however i ran into a problem with date and time.

I have an class called MtrRdngDocERPRsltCrteReqRslt having 2 fields called ActualMeterReadingDate and ActualMeterReadingTime. When Visual Studio generated the proxy class, it converted these objects as datetime objects, however I know they are Date and Time on the other end of the webservice (which is implemented in JAVA).

The problem is that when I pass datetime values to these fields, they are not getting serialized and are not being received on the other end.

Also note that when i serialize dates that are defined as DateTime by the webservice, these work perfectly.

I have also used the following code to serialize the whole object and save it locally as xml on and I have the same problem.


public void SerializeToXML(MeterReadingUploadWS2.MtrRdngDocERPRsltBulkCrteReqMsg bb, string path)
{
 System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(bb.GetType());

            var serializer = new System.Xml.Serialization.XmlSerializer(bb.GetType());

            using (var writer = System.Xml.XmlWriter.Create(path))
            {                        
                serializer.Serialize(writer, bb);
            }
        }
share|improve this question
 
can you show us what the bb object looks like when you serialize it locally to xml. –  Jethro Jul 18 '11 at 7:15
add comment

1 Answer

up vote 0 down vote accepted

I had some troubles doing that some time ago, and I decided to work with long properties, because it's the closest generic interop way to achieve it, since c#'s DateTime and java's Date objects are different things from different languages.

share|improve this answer
 
so you mean you convert dates to Long? –  TopDev Jul 19 '11 at 8:40
 
We opted to change the webservice so it accepts date and time in agreed string formats. I think its the simplest. To avoid such a problem in the future I will make sure that only datetimes are exposed in a webservice. –  TopDev Jul 20 '11 at 8:06
 
Yes, converting it to long. Both approaches (using Long or String) fits your needs anyways :) Could you mark the answer as accepted? –  Everton Agner Jul 21 '11 at 17:25
 
Serialization of dates or timestamps in XML should always be in ISO-8601 format, no exceptions. That is the best way to avoid ambiguities. –  pharsicle Jan 15 at 23:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.