Is it possible to set the request/response format in web.config?

社会主义新天地 提交于 2019-12-11 09:54:43

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/12902319/is-it-possible-to-set-the-request-response-format-in-web-config

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!