【问题标题】:Can't access JSON output via URL无法通过 URL 访问 JSON 输出
【发布时间】:2016-05-02 21:07:58
【问题描述】:

当访问我的本地主机上的 URL /Resources/Feeder.svc 时,我得到了服务响应。但是,我无法访问 /Resources/Feeder.svc/ping,尽管我使用的是以下代码。

[ServiceContract]
public interface IFeeder
{
  [WebInvoke(Method = "GET", 
    ResponseFormat = WebMessageFormat.Json, 
    UriTemplate = "ping")]
  [OperationContract]
  string Ping();
}

public class Feeder : IFeeder { public string Ping() { return "pung"; }

我一直在尝试使用和不使用一堆属性,尝试使用和不使用 svc 等访问服务。Nada。我画的是空白。

我尝试关注a guidetwo,但我根本看不到我错过了什么。

我得到的是空的点击 - 根本没有文字。错误提示 400 bad request。什么都不告诉我...我能做些什么来调试它?很可能这真的很愚蠢,因为我累了。对不起……

【问题讨论】:

    标签: json wcf rest


    【解决方案1】:

    你还没有显示你的 web.config,我猜你可能忘了编辑它。你需要做两件事。首先,声明一个端点行为。其次,添加协议映射。像这样。

    <system.serviceModel>
      <!-- Addition of protocol mapping -->
      <protocolMapping>
        <add scheme="http" binding="webHttpBinding"/>
      </protocolMapping>
      <!-- End of addition -->
      <behaviors>
        <!-- Addition of endpoint behavior -->
        <endpointBehaviors>
          <behavior>
            <webHttp />
          </behavior >
        </endpointBehaviors>
        <!-- End of addition -->
        ...
      </behaviors>
      ...
    </system.serviceModel>
    

    另外,如果您使用WebGet,我认为您实际上不需要属性OperationContract。这是多余的。

    【讨论】:

      猜你喜欢
      • 2019-07-11
      • 1970-01-01
      • 2021-03-21
      • 1970-01-01
      • 2019-04-07
      • 2021-03-17
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多