Is it possible to set the request/response format

2019-08-11 08:45发布

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)]

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

标签: wcf .net-4.0
1条回答
小情绪 Triste *
2楼-- · 2019-08-11 09:10

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>
查看更多
登录 后发表回答