wcf - 无法使用 Fiddler 将 JSON 发布数据传递到 WCF REST 服务

标签 wcf fiddler wcf-rest

我正在尝试调用 WCF 剩余服务,如下所示:

[WebInvoke(UriTemplate = "Login", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string Process(string AuthenticationInfo)
{

我正在尝试在 Fiddler 2 中使用以下内容调用它:

User-Agent: Fiddler
Host: localhost
content-type: application/json;charset=utf-8
content-length: 0
data: {"AuthenticationInfo": "data"}

我在方法中有一个断点,它确实遇到了断点,但 AuthenticationInfo 的值始终为空,而不是“数据”。

我做错了什么?

谢谢。

最佳答案

[WebInvoke] 属性的默认“body style”是“Bare”,这意味着输入(在你的例子中,“data”)必须是“按原样”发送。您发送的是输入的包装版本(即,包装在一个对象中,该对象的键是参数名称。

有两种方法可以实现此目的:要么更改 WebInvoke 声明以包含 BodyStyle 参数:

[WebInvoke(
    UriTemplate = "Login", 
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public string Process(string AuthenticationInfo)   

或者你可以改变发送参数“bare”的请求:

POST .../Login HTTP/1.1
User-Agent: Fiddler
Host: localhost
Content-Type: application/json;charset=utf-8
Content-Length: 6

"data"

关于wcf - 无法使用 Fiddler 将 JSON 发布数据传递到 WCF REST 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10290210/

相关文章:

c# - app.config 中的 maxReceivedMessageSize 和 maxBufferSize

http - 如何在 Fiddler 中显示 HTTP 请求的大小?

c# - RequestInterceptor 和 MessageInspector 有什么区别?

c# - 如何在 Windows XP 中配置 Windows Activation Server (WAS) 来承载 WCF 服务?

c# - 处理远程连接时要听什么 ip? 127.0.0.1 还是实际 IP?

javascript - 如果列没有数据, Bootstrap 表删除行

python请求响应位置

proxy - 我可以使用 Fiddler 脚本修改 JSON 响应吗

c# - 使用动态返回的列绑定(bind)列表

wcf - Azure端点-不同的部署