在浏览器中显示json的结果

时间:2016-06-06 16:16:58

标签: c# json visual-studio wcf

我创建了一个WCF服务,我想这是有效的,因为当我启动 String txt1="Health: "; SpannableString txtSpannable= new SpannableString(txt1); StyleSpan boldSpan = new StyleSpan(Typeface.BOLD); txtSpannable.setSpan(boldSpan, 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.append(txtSpannable); String txt2="good"; builder.append(txt2); textview1.lblStatus.setText(builder, TextView.BufferType.SPANNABLE); 测试的客户端打开时。然后我调用我的方法,并在JSON(测试的客户端窗口)中获取正确的数据。

但是当我启动所有proyect时,我不知道如何访问JSON的url,以便通过Mozilla检查JSON的数据...我需要这个url来了解如何设置Retrofit的值(android )用于消费WCF。

- Service1.svc.cs -

Services1.svc.cs

- Iservice -

[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "pisosA/")]
public String devolverPisosA()
    {
        List<pisosAlquiler> consultaPA = (from piso in contexto.pisosAlquiler
                          select piso).ToList();

        string json = JsonConvert.SerializeObject(consultaPA);

        return json;

    }

谢谢Mates ......

编辑:

我将在Android中使用此WCF,但它没关系。 首先,我需要获取通过浏览器查看JSON的URL。 然后,我必须使用baseURL设置Retrofit并获取Method,但我会(我希望)通过前一个url获取它们。

1 个答案:

答案 0 :(得分:0)

那么,

最后我得到了解决方案。愚蠢的一个......当我有一个anottations时,我不必序列化数据结果。只需返回对象列表......

#set( ${startbrace} = '{' )

然后我可以使用http://localhost:8080/Service1.svc/pisosA

通过浏览器观看JSON结果

感谢Mates。