我可以做以下事情吗?
[OperationContract]
[WebGet(UriTemplate = "/foo/{id}")]
string GetFoo(int id);
我希望我的服务既可以作为RESTful服务,也可以作为RPC式SOAP服务。如果可能的话,我希望将int保留为int,而不是手工解析。
发布于 2009-02-18 15:43:24
如果我没记错的话,在使用WebGet或WebInvoke时,路径中的UriTemplate变量总是解析为字符串。只有当UriTemplate变量位于UriTemplate的查询部分时,才能将它们绑定到int、long等。
发布于 2009-05-05 00:55:56
正如dthrasher提到的,将id移动到URI的查询部分。这对我很有效:
[OperationContract]
[WebGet(UriTemplate = "/foo?id={id}")]
string GetFoo(int id);
有关URI的不同部分的更多信息,请参阅维基百科上的"URI方案“:http://en.wikipedia.org/wiki/URI_scheme
发布于 2009-02-13 14:02:27
不幸的是,如果您想要使用UriTemplate
,您必须自己进行解析。
https://stackoverflow.com/questions/545988
复制相似问题