是否可以在web.config中设置请求/响应格式?

时间:2012-10-15 19:05:39

标签: wcf .net-4.0

我的WCF REST服务上有很多端点。它们都具有相同的体型,请求格式和响应格式。

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

无论如何都要在web.config中设置这些属性吗?

1 个答案:

答案 0 :(得分:2)

您可以在<webHttp>端点行为(见下文)中为正文样式和传出响应格式(不是请求格式)设置默认值。请注意,如果您在服务中(这似乎是您的情况),那无关紧要,因为WCF REST端点可以接收XML和JSON中的请求 - RequestFormat属性仅在其在< em> client ,决定发送请求的格式。

<endpointBehaviors>
    <behavior name="WebWithDefaults">
        <webHttp defaultOutgoingResponseFormat="Json"
                 defaultBodyStyle="Bare" />
    </behavior>
</endpointBehaviors>
相关问题