【发布时间】:2015-04-01 15:02:12
【问题描述】:
来自客户的 WSDL 文件使用以下语法指定时间数据类型:<xsd:simpleType name="time"><xsd:restriction base="xsd:time"><xsd:pattern value="[0-9]{2}:[0-9]{2}:[0-9]{2}"/></xsd:restriction></xsd:simpleType>
我将 WSDL 文件作为“Web 参考”(不是服务参考)包含在 Visual Studio C# 项目中。生成此代码:
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="time")]
public System.DateTime I_TIMETO {
get {
return this.i_TIMETOField;
}
set {
this.i_TIMETOField = value;
}
}
问题在于,在生成的负载中,WSDL 文件中的模式 ([0-9]{2}:[0-9]{2}:[0-9]{2}) 被完全忽略. IE。有效载荷如下所示:
<I_TIMETO xmlns="">17:11:00.0000000+01:00</I_TIMETO>
代替:
<I_TIMETO xmlns="">17:11:00</I_TIMETO>
无法更改 Web 服务,我不想更改自动生成的代码。
【问题讨论】:
-
我不是专家,但我使用的是 WCF 服务,并且认为无法将格式存储在 DateTime 中。我所做的只是传递 DateTime 变量,服务会自行计算出来。另一方面,如果我要传递 DateTime 的字符串值,我需要在客户端和服务器之间有一个标准格式字符串。
-
遗憾的是,它是一个 SAP 网络服务,所以我无法更改界面。
标签: c# visual-studio-2013 wsdl time-format