如何指定自动生成WSDL“日期”数据类型? [英] How to specify 'date' DataType for autogenerated WSDL?

查看:510
本文介绍了如何指定自动生成WSDL“日期”数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个日期(而不是DATETIME)传递到Web服务,

I need a date (not a dateTime) to be passed to a web service,

我试过这样的:

[WebMethod]
public void myMethod([XmlElementAttribute(DataType = "date")] DateTime someDate)
{
  // ...
}

但它仍然产生:

<tns:myMethod xsi:type="tns:myMethod">
    <someDate xsi:type="xsd:dateTime">dateTime</someDate>
</tns:myMethod>

任何想法?

推荐答案

在.NET中,连System.DateTime.Date是一个DateTime数据类型(的载文)。有因为没有在.NET中的时间的日期数据类型没有这样的事。

In .NET, even the System.DateTime.Date is a DateTime data type (documentaiton). There is no such thing as a "Date" datatype without the time in .NET.

日期时间的日期部分将评估该日期的午夜,D

The date portion of a DateTime will evaluate to midnight of that date, d

DateTime DateOnly = DateTime.Now.Date;
Console.Out.WriteLine(DateOnly.ToString("yyyy-MM-dd hh:mm:ss");

将写出

2012年9月10日00:00:00

2012-09-10 00:00:00

在你的code,您可以访问刚使用上面的code中的日期,但无论如何,这将是一个DateTime值。

Within your code you can access just the date using the code above, but regardless, it's going to be a DateTime value.

当然,SOAP编码确实有一个日期数据类型,但是.NET无关,它匹配,除了datetime数据类型。

Of course, SOAP Encoding does have a Date datatype, but .NET has nothing to match it to, other than the DateTime Data Type.

除非你写你自己的数据类型,这可能将是浪费大量的时间。

这篇关于如何指定自动生成WSDL“日期”数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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