Java Webservice 和 .NET 客户端丢弃 DateTime 对象

标签 java .net web-services wsdl

在 Java Web 服务和与之通信的 .NET 客户端之间看到一些奇怪的东西。我们正在来回发送一个带有 DateTime 属性的对象。有点像这样(从 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 的标签不存在,有点像这样:

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

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

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

我们对其他事物使用相同的类型,效果也很好。在 .NET 方面,我们使用 wsdl.exe 工具生成类和代码。

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

最佳答案

当模式中的值类型是可选的时,WSDL.EXE 会为该值生成一个属性,并生成一个 bool 属性以指示该值是否存在。您应该有一个 ExpirationSpecified 属性,当您想要发送到期日期时需要将其设置为 true,如果您不想发送则设置为 false

关于Java Webservice 和 .NET 客户端丢弃 DateTime 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/677754/

相关文章:

java - 如何使用 REST Web 服务将图像存储在 MySQL 数据库中

java - 将 JSONObject 中的文件发送到 REST WebService

java - 经度和纬度显示 0.0

java - 如何解决我在 Apache Poi 和 Excel 中的问题

java - Java 中 2 位运算符的强大功能?

c# - 设置 DatagridView 行以关注表单加载

java - 创建 @ApplicationScoped 计划进程的最佳方法

c# - 通过 SSL 的 HttpWebRequest?

c# - InterruptedException (Java) 的 .NET 等价物是什么?

web-services - API 与 Web 服务