是否有可能设置在web.config中的请求/响应的格式? [英] Is it possible to set the request/response format in web.config?

查看:181
本文介绍了是否有可能设置在web.config中的请求/响应的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的WCF REST服务相当多的端点。它们都具有相同的机身风格,请求格式和响应格式。

I have quite a few endpoints on my WCF REST Service. They all have the same body style, request format and response format.

[WebGet(BodyStyle = WebMessageBodyStyle.Bare,
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json,
    UriTemplate = xxx)]

反正是有设定这些属性在web.config?

Is there anyway to set those attributes in the web.config?

推荐答案

您可以设置的默认的价值,为车身造型和即将离任的响应格式(不是为请求格式)的< webHttp> 终结点行为(见下文)。请注意,如果你在一个服务(这似乎是您的情况),这也不要紧,因为WCF REST端点可以接收XML和JSON请求 - 在RequestFormat属性时,它被内使用只用客户的,来决定以哪种格式发送请求。

You can set the default value for the body style and for the outgoing response format (not for the request format) in the <webHttp> endpoint behavior (see below). Notice that if you're in a service (which seems to be your case), that doesn't matter, since WCF REST endpoints can receive requests in both XML and JSON - the RequestFormat property is only used when it's being used within a client, to decide in which format to send the request.

<endpointBehaviors>
    <behavior name="WebWithDefaults">
        <webHttp defaultOutgoingResponseFormat="Json"
                 defaultBodyStyle="Bare" />
    </behavior>
</endpointBehaviors>

这篇关于是否有可能设置在web.config中的请求/响应的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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