【问题标题】:How should the Request Body look like?请求正文应该是什么样子?
【发布时间】:2009-03-17 11:16:53
【问题描述】:

我有一个 WCF 服务,它的方法看起来像这样(返回 null 以使用调试器进行测试,我现在只关心获取数据):

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "fares", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public List<Fare> GetFares(Dictionary<int, int> itineraries, decimal? threshold, bool includeInternational)
{
    return null;
}

我正在尝试使用 Fiddler 向该方法发出请求,但无法弄清楚正确的请求正文应该是什么。如果效果更好,我可以将 Dictionary 参数更改为其他参数。

在请求标头中我通过:

用户代理:提琴手
内容类型:应用程序/json;字符集=utf-8

我应该在身体里放什么?

【问题讨论】:

    标签: wcf json request fiddler


    【解决方案1】:

    我想这就是你所追求的。

    {
    "itineraries" : [{"Key":1,"Value":2},{"Key":2,"Value":3}],
    "threshold" : 1.0,
    "includeInternational" : true
    }
    

    字典序列化为键值数组。

    【讨论】:

    • 我在 Fiddler 中明确将此设置为 POST 请求,因此数据不会作为 URI 的一部分发送。问题是在 Fiddler 中我想手动输入数据并且不知道它的外观,所以我最终会遇到服务器端异常。
    • 对不起,我错过了这个问题并更新了我的答案。我认为上面的 json 是你所追求的。如果您还没有收到异常,请在 web 配置中打开 system.diagnostics。
    猜你喜欢
    • 2020-01-30
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    相关资源
    最近更新 更多