Rya*_*son 8 c# wcf json webhttpbinding
我正在编写一个有很多方法的Web服务.它们都设置类似于以下内容:
[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "x/y/z")]
void someMethod(int x, int y, int z);
Run Code Online (Sandbox Code Playgroud)
我想要做的只是在web.config文件中设置默认的BodyStyle/ RequestFormat/ ResponseFormatall.现在,我知道我可以这样做:
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
Run Code Online (Sandbox Code Playgroud)
但似乎没有RequestFormat的属性.如何将默认设置RequestFormat为JSON?
请求类型由WCF自动解释,您无需RequestFormat为服务操作指定默认值.
如果您尝试强制执行支持的请求格式,请参阅有关强制执行请求内容类型的相关SO帖子.
注意:RequestFormat为WebGet操作分配一个没有意义.根据定义,a WebGet不能包含BodyJSON格式存在的位置.这里有一个更好的例子WebInvoke.
| 归档时间: |
|
| 查看次数: |
8066 次 |
| 最近记录: |