传递一个DateTime参数ASP.NET Web服务 [英] Passing a DateTime parameter to ASP.NET Web Service

查看:294
本文介绍了传递一个DateTime参数ASP.NET Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能为DateTime参数发布到ASMX Web服务内的Web方法(使用JSON序列化的RPC样式调用)?

Is it possible to post a DateTime parameter to a Web Method inside an ASMX web service (using a JSON serialized RPC style call)?

我送一个DateTime到浏览器,这被形式/日期(1350639464100 + 0100)/序列化。然后我就可以使用优秀的 moment.js 库来解析日期,网页等上显示它​​。

I am sending a DateTime to the browser and this gets serialized in the form /Date(1350639464100+0100)/. I can then use the excellent moment.js library to parse the date, display it on the page etc.

我的问题是这样返回日期使用AJAX后到我的Web服务的服务器。我的Web方法看起来是这样的:

My problem is returning this date to the server using an AJAX post to my web service. My web method looks something like this:

[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void Save(DateTime date)
{
    // Do stuff
}

如果我尝试在相同的格式发送的日期,因为它下来(/日期(1350639464100 + 0100)/),然后我得到一个错误:

If I try to send a date in the same format as it came down (/Date(1350639464100+0100)/) then I get an error:

/日期(1350639464100 + 0100)/不是日期时间的有效值。

在那里发送此成一个字符串,然后解析服务器上的价值的任何更好的方法?理想情况下,我想能够发送一个往返,并从服务器对象,而无需改变任何日期属性,它们可能含有。

Are there any better alternatives to sending this up as a string and then parsing the value on the server? Ideally I'd like to be able to send objects on a round trip to and from the server without having to alter any date properties that they may contain.

感谢您的帮助!

推荐答案

您可以更改参数类型为字符串,然后您可以将该字符串转换成你想要的任何类型的

You can change the parameter type to string and then you can convert that string to any type you want

   public void Save(String date){
     *Code*
    }

这篇关于传递一个DateTime参数ASP.NET Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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