【问题标题】:Show json´s result in browser在浏览器中显示 json 的结果
【发布时间】:2016-06-06 16:16:57
【问题描述】:

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

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

--Service1.svc.cs--

[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;

    }

--Iservice--

[OperationContract]
String devolverPisosA();

谢谢大佬...

已编辑:

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

【问题讨论】:

  • 测试客户端中的地址是什么...?
  • 测试客户端是 Visual Studio 打开的一个窗口,允许您测试 WCF 用途。它在你运行 WCF 的类时打开。
  • 所以你的问题不太清楚——你需要从哪里消费这个服务?
  • 在 Android 中,但没关系。首先,我需要获取通过浏览器查看 JSON 的 url。然后,我必须使用 baseURL 设置 Retrofit 并获取 Method,但我会(我希望)通过之前的 url 获取它们。

标签: c# json visual-studio wcf


【解决方案1】:

嗯,

我终于找到了解决方案。愚蠢的......当我有注释时,我不必序列化数据结果。只需返回对象列表...

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

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

谢谢大佬。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-13
    • 1970-01-01
    • 2018-12-15
    • 2018-02-01
    • 1970-01-01
    • 2021-04-09
    • 2016-07-02
    • 2014-11-11
    相关资源
    最近更新 更多