1

我可以使用邮递员在 wcf 休息服务中使用该方法。

但是当我点击 API 时我正在使用 JIRA webhook 它给了我 400 错误

  Client error - 400 when posting to web hook at 'http://localhost:12456/JiraRestWebhook.svc/GetData/TES-217?user_id=james&user_key=jamesD'

我的方法如下:

     [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json
            , UriTemplate = "GetData/{value}"
            )]
    string GetData(string value, Stream c);

我可以使用邮递员成功地击中它。该请求还包含原始数据。

但是我的 JIRA webhook 在更新/创建任何问题时给出了这个错误。

请注意:- 如果我从方法中删除 Stream Param。那么我的服务就能给我结果。

4

1 回答 1

0

在您的 WCF 界面中值得纠正的几件事: 1. 首先,您应该考虑在 WebInvoke 中添加 Method = "GET"。2. 由于您使用的是“GetData/{value}”,因此您请求的 URL 应该看起来像这样。{value} 是它将选择您作为参数传递的值字符串的地方。

'http://localhost:12456/JiraRestWebhook.svc/GetData/jamesD'
  1. 不确定为什么要传递 Stream c 以及其他参数。如果您希望在此处传递 json 请求,则需要在 WCF 服务中进行一些更改。

您的运营合同应如下所示:

 [OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json
        , UriTemplate = "GetData" //this can be anything like GetDate/Json/GeMeData
        )]
string GetData(Stream c);

您的 GetData 现在具有您需要使用反序列化转换为对象的 JSON 请求。

于 2014-07-28T22:45:56.750 回答