如何将NULL值传递给WCF数据服务的服务操作? [英] How to pass a NULL value to a WCF Data Services' service operation?
问题描述
我有WCF数据服务的服务操作,例如
I have a WCF data services' service operation such as
[WebGet(UriTemplate = "GetData")]
public IQueryable<string> GetData(int code, int deviceid, int groupId, DateTime dateTimeFrom, DateTime dateTimeTo)
{ ...
}
我通过以以下格式向服务器发送HTTP请求来调用此服务操作:
I am calling this service operation by sending a HTTP request to the server in this format:
http://localhost:6000/GetData?code=0&deviceId=1&groupId=0L&dateTimeFrom=datetime'2013-01-31T15:36:50.904'&dateTimeTo=datetime'2012-02-01T15:36:50.904'
,它的工作就像一种魅力.
现在,我想将NULL值作为参数之一传递.我怎么做?我是否需要使用可为null的类型,例如"Int"?在服务操作声明中?如何在URI中编码NULL值?
and it is working like a charm.
Now I want to pass a NULL value as one of the parameters. How do I do that? Do I need to use nullable types such as "Int?" in the service operation declaration? How do I encode the NULL value in the URI?
推荐答案
是-您需要将参数声明为可为空.然后,您可以简单地省略该参数(如果该参数可为空,则将其视为null).
Yes - you need to declare the parameter as nullable. Then you can simply omit the parameter (if it's nullable it will be treated as null then).
这篇关于如何将NULL值传递给WCF数据服务的服务操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!