0

I understood that UriTemplate supports only string parameters unless you have them in form like below (id={id} etc.). Here for example:

Can I pass non-string to WCF RESTful service using UriTemplate?

However I can't make the following work. Even if I change 2nd parameter to string (not string array). Is this kind of operation callable from a browser by typing URL in address-field?

[WebGet(ResponseFormat = WebMessageFormat.Json, 
        UriTemplate = "id={id}/legend={legend}/x={x}/y={y}")]
public Stream GetMapPicture(int id, string[] legend, double x, double y)

All works if I change parameters to strings and type:

http://localhost:8732/Service1/id=732/legend=[343434, 555]/x=43/y=23

Thanks!

4

1 回答 1

1

我在问题中的链接中有一个答案:

我可以使用 UriTemplate 将非字符串传递给 WCF RESTful 服务吗?

String[]

可能应该是必须解析/反序列化的字符串。

然而,一个 int 和一个 double 它看起来像这样:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    Stream GetMapPicture(int id, double x);
…
 public class Service1 : IService1
 {
    [WebGet(ResponseFormat = WebMessageFormat.Json, 
        UriTemplate = "MapPicture/?id={id}&x={x}")]
    public Stream GetMapPicture(int id, double x)
    {

然后像这样从浏览器中消耗它:

http://localhost:8732/service1/MapPicture/?id=3&x=6.21

因为没有人将此标记为重复,所以我也在这里发布了答案。与链接的不同之处在于,这里是两个参数与与号 (&) 组合

-m

于 2014-09-11T12:10:35.180 回答