WCF REST return single method as JSON and XML

前端 未结 3 1061
灰色年华
灰色年华 2020-12-09 00:32

I am using below Code for WCF Rest Services to get in JSON format

[OperationContract]   

[WebGet(UriTemplate = \"/GetOrderList?request={request}\", BodyStyl         


        
3条回答
  •  无人及你
    2020-12-09 00:45

    If you were using .NET 4.0 or 4.5, then it would be simple - either use the automatic format selection as suggested by Vibin Kesavan, or within the operation set the WebOperationContext.Current.OutgoingResponse.Format to either JSON or XML depending on some of your logic.

    For 3.5, you need to do most of the work. This post has an implementation exactly of this scenario. You need to create a custom dispatch message formatter implementation which (likely) wraps two formatters, one for JSON and one for XML. And when serializing the response, decide which formatter to use based on your logic.

提交回复
热议问题