【发布时间】:2014-09-16 06:42:07
【问题描述】:
我正在使用 fiddler 向 WCF Web 服务发送 POST 请求,该服务以 HTTP 400 响应:请求的标头名称无效。 发布请求如下所示:
User-Agent: Fiddler
Host: localhost:49392
Content-Type: application/json
Content-Length: 0
{ "clientFirstName" : "John"}
我的端点定义如下:
[OperationContract]
[System.ServiceModel.Web.WebInvoke
(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json,
BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped,
UriTemplate = "MakeReservation")]
String MakeReservation(Stream reservationStream);
更多
首先,JSON 在错误的窗格中。我将其移至“请求正文”窗格。
我更改了函数的原型,以使用 String 而不是 Stream 作为输入参数。该服务现在接受我的调用并返回 200,但在调试器中我看到输入参数 String 为空。当我将它改回 Stream 时,我又得到了 400。
还有更多
启用跟踪在跟踪文件中为我提供以下消息:
Incoming message for operation 'MakeReservation' (contract 'ITalLimoService' with namespace
'http://tempuri.org/') contains an unrecognized http body format value 'Json'. The expected body
format value is 'Raw'. This can be because a WebContentTypeMapper has not been configured on the
binding. See the documentation of WebContentTypeMapper for more details.
如 WebInvoke 定义中所述,RequestFormat 和 ResponseFormat 都设置为 WebMessageFormate.Json。为什么 IIS 抱怨这个?
【问题讨论】:
-
您的第一个块中的数据格式错误;您在标题中显示 JSON 文本,并且当您清楚地发送内容时,您有一个
Content-Length: 0。请更新您的问题,以便我们准确了解您在做什么。