积极答复者
WCF4.0中REST模式下,URI与其相对应的方法参数是否只能为string?

问题
-
如题描述:代码如下
[WebGet(UriTemplate = "{id}")] public SampleItem Get(string id) { // TODO: Return the instance of SampleItem with the given id throw new NotImplementedException(); }
Get方法中参数设置为int就报错说只能为string,记得在3.5版本下面的REST可以自己转换类型的;现项目是3.5的希望升级到4.0,N多方法参数是int类型的,囧;
刚用Refector翻一下源码也没找到,希望斑竹解答一下。
答案
-
可以为其它。NET数据类型吧,我没测试过,比如你设置为GUID类型,转换的时候会做检查吧。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
- 已标记为答案 叶忝 2011年7月22日 1:49
全部回复
-
可以为其它。NET数据类型吧,我没测试过,比如你设置为GUID类型,转换的时候会做检查吧。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
- 已标记为答案 叶忝 2011年7月22日 1:49
-
可以为其它。NET数据类型吧,我没测试过,比如你设置为GUID类型,转换的时候会做检查吧。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
微软WCF中文技术论坛
微软WCF英文技术论坛
Windows Azure中文技术论坛 -
问题解决了,没注意UriTemplate 的详细说明,对于我的问题可以通过"?id={id}的方法,
直接{id}的对应参数是只能为string;
http://msdn.microsoft.com/zh-cn/library/bb675245.aspx