REST 具有可空类型?
我碰壁了。我的 REST 实现不接受 Nullable 值。
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Transactions?AccNo={AccNo}&CostCentreNo={CostCentreNo}&TransactionType={TransactionType}&Outstanding={Outstanding}&CheckStartDate={CheckStartDate}&CheckEndDate={CheckEndDate}")]
List<Transactions> GetTransactions(Int32 AccNo, Int32 CostCentreNo, Int32 TransactionType, Boolean Outstanding, DateTime? CheckStartDate, DateTime? CheckEndDate);
而我原来的 SOAP 实现却是这样。那么有办法解决这个问题吗?或者我必须重新编写我的代码?
我仍然不太明白为什么日期时间必须可以为空才能设置为空。
I've hit a brickwall. My REST implementation won't accept Nullable values.
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Transactions?AccNo={AccNo}&CostCentreNo={CostCentreNo}&TransactionType={TransactionType}&Outstanding={Outstanding}&CheckStartDate={CheckStartDate}&CheckEndDate={CheckEndDate}")]
List<Transactions> GetTransactions(Int32 AccNo, Int32 CostCentreNo, Int32 TransactionType, Boolean Outstanding, DateTime? CheckStartDate, DateTime? CheckEndDate);
Whereas my original SOAP implementation does. So is there a way around this? Or do I have to re-write my code?
I still don't quite get why a datetime must be nullable anyway to be set to null.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UriTemplate 查询值的变量必须具有可由 QueryStringConverter 转换的类型。可空类型则不然。
您可以包装参数并通过 POST 传递它;
或者,您可以将日期作为字符串而不是 DateTime 传递,然后在接收端的字符串上使用 DateTime.Parse() 。
Variables for UriTemplate query values must have types that can be converted by QueryStringConverter. Nullable types is not.
You could wrap the parameters and pass it through POST as such;
Opionally, you could pass the date as strings instead of DateTime, and then use DateTime.Parse() on the string on the receiving end.