首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在浏览器中显示json的结果

在浏览器中显示json的结果
EN

Stack Overflow用户
提问于 2016-06-06 16:16:57
回答 1查看 123关注 0票数 0

我创建了一个WCF服务,我想是因为我启动Services1.svc.cs测试的客户端是打开的。然后调用我的方法,并在JSON (测试的客户端窗口)中获得适当的数据。

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

-Service1.svc.cs--

代码语言:javascript
运行
复制
[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;

    }

-服务

代码语言:javascript
运行
复制
[OperationContract]
String devolverPisosA();

谢谢朋友们..。

编辑:

我将在Android中使用这个WCF,但它并不重要。首先,我需要通过浏览器获取查看JSON的url。然后,我必须用baseURL和get方法来设置Retrofit,但是我会(我希望)在前面的url中得到它们。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-11 07:51:29

井,

我终于找到解决办法了。愚蠢的那个..。当我有指定时,我不需要序列化数据结果。只需返回对象列表..。

代码语言:javascript
运行
复制
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "pisosA")]
public String devolverPisosA()
    {
        List<pisosAlquiler> consultaPA = (from piso in contexto.pisosAlquiler
                          select piso).ToList();

        return consultaPA;

    }

<system.serviceModel>
    <services>
      <service name="ProyectoJosephWCF.Service1" behaviorConfiguration="ServiceBehavior">
        <endpoint binding="webHttpBinding"
                  contract="ProyectoJosephWCF.IService1"
                  behaviorConfiguration="webHttp"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>

        <behavior name="ServiceBehavior" >
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>


        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>

然后,我可以使用http://localhost:8080/Service1.svc/pisosA浏览器查看JSON结果。

谢谢各位朋友。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37662259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档