【问题标题】:Not able to access any mothod with the attribute [WebInvoke] in WCF Restful services无法访问 WCF Restful 服务中具有属性 [WebInvoke] 的任何方法
【发布时间】:2012-04-16 09:58:12
【问题描述】:

我无法在 RESTful WCF 服务中使用属性 [webinvoke] 访问任何方法。

我的代码是这样的:

[OperationContract]
[WebInvoke(Method = "Post", UriTemplate = "Comosite/{composite}", ResponseFormat = WebMessageFormat.Xml)]
CompositeType GetDataUsingDataContract(string composite);        

在执行上述服务时,我收到一条错误消息

方法不允许。

我尝试了很多方法,修改了 urltemplate、方法名称和方法类型等,但没有任何结果。

但如果我使用[WebGet] 属性,服务方法工作正常。

任何人都可以建议我怎样做才能使它工作吗?

提前谢谢... :)

【问题讨论】:

  • 问题是我想执行 post/put/delete 操作。使用 get 我可以从服务中获取日期,但问题是我只是不想获取数据,我想对数据执行更新和删除操作。为此,我正在使用 webinvoke 和 post 方法进行测试。如果 post 方法工作正常,那么我可以继续 delete 和 put 方法。
  • 你能展示一些你用来调用你的服务的代码吗?
  • 我使用 HTTPClient 对象与服务进行通信。它适用于 Get 方法。
  • 服务调用代码如下。

标签: wcf service webinvoke


【解决方案1】:

尝试改变

[WebInvoke(Method = "Post", UriTemplate = "Comosite/{composite}", ResponseFormat = WebMessageFormat.Xml)]

[WebInvoke(Method = "POST", UriTemplate = "Comosite/{composite}", ResponseFormat = WebMessageFormat.Xml)]

【讨论】:

    【解决方案2】:

    我创建了一个与您在此处所做的类似的服务,并用 fiddler 调用它,当我将方法更改为 POST 所有大写字母时,它就起作用了。当方法类似于您的代码中的 Post 时,我会收到未找到端点的消息。

    我的提琴手请求如下所示:

    http://localhost/service/service1.svc/Comosite/test 
    

    这里测试作为复合参数发送,我得到一个 CompositeType 作为 xml 返回。

    【讨论】:

      猜你喜欢
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多