Java Webservice和.NET客户端删除DateTime对象 [英] Java Webservice and .NET client dropping DateTime objects

查看:60
本文介绍了Java Webservice和.NET客户端删除DateTime对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看到Java Web服务和与其通信的.NET客户端之间有些奇怪的事情.我们正在来回发送带有 DateTime 属性的对象.像这样(从WSDL生成):

Seeing something strange between a Java web service and the .NET client talking to it. We are sending an object back and forth with a DateTime property on it. Sort of like this (generated from the WSDL):

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://ournamespace.com/")]
public partial class myClass {
    private System.DateTime expirationDateField;
    private string nameField;

    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public System.DateTime expirationDate {
        get {
            return this.expirationDateField;
        }
        set {
            this.expirationDateField = value;
        }
    }

    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }
}

我们收到的对象的日期很好,但是当我们将它们发送回Web服务时, expirationDate 属性显示为 null .我们查看了Java服务器接收到的原始XML,但没有找到 expirationDate 的标签,就像这样:

We are receiving the objects with dates just fine, but when we send them back to the Web Service, the expirationDate property was showing up as null. We looked at the raw XML that the Java server was receiving and the tag for expirationDate wasn't there, sort of like this:

<myClass><name>My Name</name></myClass>

(这不是确切的XML,但足够接近).我仔细检查了一下,在发送前肯定在.NET客户端上设置了 expirationDate .WSDL的XSD看起来并不奇怪:

(That's not the exact XML, but close enough). I double checked and expirationDate is definitely set on the .NET client before being sent. The XSD for the WSDL doesn't look strange:

<xs:element name="Expiration" type="xs:dateTime" minOccurs="0"/>

我们在其他事情上使用了相同的类型,也可以正常工作.在.NET方面,我们使用 wsdl.exe 工具生成类和代码.

We are using the same type for other things, which work fine as well. On the .NET side, we're using the wsdl.exe tool to generate the classes and code.

我们可以采取的下一步是在.NET调用Web服务之前查看它生成的XML,但是我不知道该怎么做.还有其他想法或建议吗?

One more step we could take would be to see the XML that is generated by .NET before it calls the web service, but I don't know how to do that. Any other thoughts or suggestions?

推荐答案

当架构中的值类型为可选时,WSDL.EXE会为该值生成一个属性,并为一个bool属性来指示该值是否存在..您应该具有一个ExpirationSpecified属性,该属性需要在发送到期日期时设置为 true ,而在不发送时设置为 false .

When a value type is optional in the schema, WSDL.EXE generates a property for the value, and a bool property to indicate whether the value is present or not. You should have an ExpirationSpecified property that needs to be set to true when you want to send the expiration date, and false when you do not.

这篇关于Java Webservice和.NET客户端删除DateTime对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆