【问题标题】:does not contain definition for "Method"不包含“方法”的定义
【发布时间】:2015-12-02 12:13:22
【问题描述】:

我有一个带有 SOAPRESTful 端点的 WCF 应用程序,我遵循 this 教程。

一切都很好,我可以打电话给basicHttpbinding data。现在我正在尝试从RESTful 端调用数据,编码时收到此错误

错误 1“System.ServiceModel.Web.WebGetAttribute”不包含“方法”的定义

错误显示在这里:

[OperationContract]
    [WebGet(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getTrucksA")]
    List<RTrucks> GetTrucksA();

我确实在 Stack Overflow 上查看了 this 问题并尝试了所有答案,例如

  • 删除using System.ServiceModel.Web 并重新添加。

  • 添加参考

  • 在我的项目设置中更改框架目标

    但没有任何效果。

有什么想法吗?

【问题讨论】:

    标签: c# wcf rest soap


    【解决方案1】:

    WebGetAttribute 没有名为 Method 的属性。无需将方法设置为WebGet 始终引用GET 请求。所以删除 Method = "Get", 部分就可以了。

    【讨论】:

      【解决方案2】:

      MS 定义的WebGet 不需要您发布的 Method = 'Get',因为 WebGet 用于动词 GET,您可以使用 WebInvoke(Method='POST') 进行 POST。

      【讨论】:

      • 是的,愚蠢的错误,我应该使用 WebInvoke。 @wjvander 谢谢。
      猜你喜欢
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      相关资源
      最近更新 更多