Search code examples
javac#web-servicesserializationsap-erp

Serialize c# DateTime to Java Time and Java Date for SAP webservice


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);
            }
        }

Solution

  • 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.