传递流时Wcf Rest Service错误

时间:2014-07-25 15:02:48

标签: wcf wcf-rest jira-rest-api

我可以使用邮递员在wcf rest服务中点击该方法。

但是当我点击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。然后我的服务能够给我结果。

1 个答案:

答案 0 :(得分:0)

在WCF界面中很少有值得纠正的事情: 1.首先,您应该考虑在WebInvoke中添加Method =“GET”。 2.由于您使用的是“GetData / {value}”,因此请求URL应该只是这样。 {value}是它将选择您作为参数传递的值字符串的位置。

'http://localhost:12456/JiraRestWebhook.svc/GetData/jamesD'
  1. 不确定为什么要将Stream c与其他参数一起传递。如果您希望传递json请求,则需要在WCF服务中更改一些内容。
  2. 您的操作合同应如下所示:

     [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请求。