可以从浏览器调用带有非字符串参数的WCF JSON WebService操作吗? [英] can WCF JSON WebService operation with non-string parameters be called from browser?

查看:132
本文介绍了可以从浏览器调用带有非字符串参数的WCF JSON WebService操作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道UriTemplate仅支持字符串参数,除非您采用以下形式(id = {id}等).例如:

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

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

但是,我无法进行以下工作.即使我将第二个参数更改为字符串(不是字符串数组).通过在地址字段中输入URL可以从浏览器调用这种操作吗?

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

谢谢!

推荐答案

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

There is an answer in the link i have in the question:

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

String[]

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

should probably be string which must be parsed/deserialized.

但是具有一个int和一个double的它看起来像这样:

However with one int and one double it look like this:

[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)
    {

,然后从浏览器中将其消耗掉,如下所示:

and then it's consumed from browser like this:

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

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

Because nobody tagged this as duplicate I posted an answer here also. The difference with the link is that here is two parameters combined with ampersand (&)

-m

这篇关于可以从浏览器调用带有非字符串参数的WCF JSON WebService操作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆