将 c# DateTime 序列化为 SAP Webservice 的 Java 时间和 Java 日期

发布于 2024-11-24 20:38:53 字数 1005 浏览 0 评论 0原文

我需要使用 c# 4.0 (VS2010) 中的 WCF 通过 Web 服务将数据上传到 SAP。我已经能够成功使用网络服务连接并将数据发布到,但是我遇到了日期和时间问题。

我有一个名为 MtrRdngDocERPRsltCrteReqRslt 的类,有 2 个名为 ActualMeterReadingDateActualMeterReadingTime 的字段。当 Visual Studio 生成代理类时,它将这些对象转换为日期时间对象,但我知道它们是 Web 服务(在 JAVA 中实现)另一端的日期和时间。

问题是,当我将日期时间值传递给这些字段时,它们没有被序列化,也没有在另一端被接收。

另请注意,当我序列化由 Web 服务定义为 DateTime 的日期时,这些日期可以正常工作。

我还使用以下代码来序列化整个对象并将其在本地保存为 xml,并且我遇到了同样的问题。


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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2024-12-01 20:38:53

前段时间我在做这件事时遇到了一些麻烦,我决定使用长属性,因为这是实现它的最接近的通用互操作方法,因为 c# 的 DateTime 和 java 的 Date 对象是来自不同语言的不同事物。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文