WCF WebInvoke ResponseFormat

前端 未结 2 383
醉话见心
醉话见心 2021-01-13 08:19

I have a WCF restul service and I want to allow the user to choose what request format they want, i have the decorations

    [OperationContract]
    [WebInvo         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 09:01

    No, I don't think you can do that programmatically at runtime. What you can do of course if to expose two distinct endpoints from your service - one returning XML, another returning JSON, and then programmatically pick which one to call from your client app.

    Marc

    Update: as Steve Michelotti correctly points out, this automatic switching between JSON and XML can now be achieved in WCF 4.0. WCF 4.0 has an improved REST support which also includes an Format Message Selection feature, based on HTTP accept headers.

    For more info on WCF 4.0's new features, see: A Developer's Introduction to WCF 4.0

提交回复
热议问题