我可以执行以下操作吗?
[OperationContract]
[WebGet(UriTemplate = "/foo/{id}")]
string GetFoo(int id);
我希望我的服务既可以作为 RESTful 服务,又可以作为 RPC 样式的 SOAP 服务。 如果可能的话,我想将 int 保留为 int,而不是手动进行解析。
最佳答案
正如 dthrasher 提到的,将 id 移动到 URI 的查询部分。这对我有用:
[OperationContract]
[WebGet(UriTemplate = "/foo?id={id}")]
string GetFoo(int id);
有关 URI 不同部分的更多信息,请参阅维基百科上的“URI 方案”: http://en.wikipedia.org/wiki/URI_scheme
关于.net - 我可以使用 UriTemplate 将非字符串传递给 WCF RESTful 服务吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/545988/