如何强制请求为JSON? IE.如何阻止XML正文? [英] How to force requests to be JSON? I.e. how to block XML body?

查看:134
本文介绍了如何强制请求为JSON? IE.如何阻止XML正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个REST WCF服务和一个WCF客户端应用程序.

I have a REST WCF service and a WCF client application for it.

我的操作具有以下属性的WebGet属性:BodyStyle = WebMessageBodyStyle.Bare,ResponseFormat = WebMessageFormat.Json,RequestFormat = WebMessageFormat.Json

My operation has the WebGet attribute with the following properties: BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json

但是,当我使用WCF客户端时,请求是使用XML格式的正文发出的!这是不可取的!如何将其更改为使用JSON?

However, when I use the WCF client, the request is made with the body in XML format! This is undesirable! How can I change it to use JSON?

此外,我也想阻止XML在服务器端被接受-我该如何做到这一点?我本来希望指定RequestFormat来做到这一点,但这似乎只是一个建议?

Furthermore, I want to prevent XML from being accepted on the server side, as well - how can I accomplish this? I would have expected specifying RequestFormat to do it but it appears to be just a suggestion?

没关系,我是个白痴.我正在查看错误的操作合同-正确的合同位于我未扩展的#region内...客户端工作正常.服务器点仍然有效,但是在此问题的上下文中,最好考虑将此问题关闭.

nevermind, I am an idiot. I was looking at the wrong operation contract - the right ones were inside a #region that I had not expanded... the client works fine. The server point is still valid but in the context of this question, it's probably for the better to consider this question closed.

推荐答案

没关系,我是个白痴.我正在查看错误的操作合同-正确的合同位于我尚未扩展的#region内...客户端工作正常.服务器点仍然有效,但是在此问题的上下文中,最好考虑将此问题关闭.

Nevermind, I am an idiot. I was looking at the wrong operation contract - the right ones were inside a #region that I had not expanded... the client works fine. The server point is still valid but in the context of this question, it's probably for the better to consider this question closed.

这篇关于如何强制请求为JSON? IE.如何阻止XML正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆