开发者

REST-based service - handling empty strings

I have developed a REST-ba开发者_开发技巧sed web service. This service takes four parameters. The last two of these parameters may be empty strings. My question is, what is the recommended approach for dealing with empty strings?

Thanks!


You have two options here - either define the parameters in the UriTemplate of the operation as query variables (and not path variables), or if this is not a GET operation, you can let the operation body receive them.

Case 1:

[WebGet(UriTemplate="/GetData?x={x}&y={y}&z={optional1}&w={optional2}")]
string GetData(int x, int y, string optional1, string optional2);

Case 2:

[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string DoSomething(int x, int y, string optional1, string optional2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜