繁体   English   中英

WCF数据服务[WebGet]日期时间参数

[英]WCF data service [WebGet] datetime parameters

我尝试将2个datetime参数传递到我的Webget中,但是我不知道如何使其正常工作,我将在下面向您展示我的代码,并且可能现在有人告诉我该错误如何起作用。

[WebGet]
public IQueryable<TestTable> GetCallersByDate(string beginDate, string eindDate)
{
        testCDREntities context = this.CurrentDataSource;

        DateTime startDt = DateTime.Parse(beginDate);
        DateTime endDt = DateTime.Parse(eindDate);



        var selectedOrders = from table in context.TestTables
                             where table.Created >= startDt && table.Created <= endDt
                             select table;

        return selectedOrders; 
}

网址:

http://localhost:50088/WebService.svc/GetCallersByDate?beginDate=2016/03/23T20:22:30:14&eindDate=2016/03/2T20:13:11:03

我希望有人可以帮助我吗?

根据以下数据,您应该使用DateTime.ParseExact而不是通常的DateTime.Parse

http:// localhost:50088 / WebService.svc / GetCallersByDate?beginDate = 2016/03 / 23T20:22:30:14&eindDate = 2016/03 / 2T20:13:11:03

我们可以看到日期字符串的格式为yyyy / MM / ddTHH:mm:ss和AFAIK,该格式不是.NET固有的

beginDate = 2016/03 / 23T20:22:30:14 eindDate = 2016/03 / 2T20:13:11:03

string dateFormat = "yyyy/MM/ddTHH:mm:ss";

DateTime startDt = DateTime.ParseExact(beginDate, dateFormat, CultureInfo.InvariantCulture);
DateTime endDt = DateTime.Parse(eindDate, dateFormat, CultureInfo.InvariantCulture);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM