根据 Accept 标头在函数内部设置响应格式,而不是在 REST 中使用 ResponseFormat = WebMessageFormat.Json 在外部设置响应格式
我正在使用 WCF REST Starter Kit Preview 2 中的纯旧 XML 模板来构建 REST 服务,我想在 OperationContract 内部设置 ResponseFormat,而不是在外部(不使用 ResponseFormat = WebMessageFormat.Json),因为我想相应地设置它到请求中的 Accept 标头。理想情况下,我希望能够根据 Content-Type 标头从 OperationsContract 内部设置 RequestFormat。
那么,谁能告诉我如何做到这一点,或者给我指出一些例子。
chers,
稍后编辑:所以我不想在 UriTemplate 中包含“格式”之类的内容,我只想要一个 UriTemplate,没有 ResponseFormat (并且在某些时候没有 RequestFormat)并且根据 AcceptHeader 输出 ResponseBody
[WebHelp(Comment = "For Service testing purposes")]
[WebGet(UriTemplate = "Echo")]
[OperationContract]
public ResponseBody Echo()
i am using the Plain old XML template from WCF REST Starter Kit Preview 2 to build a REST service and i would like to set the ResponseFormat inside the OperationContract, not outside(not with ResponseFormat = WebMessageFormat.Json) because i want to set it accordingly to the Accept Header in the Request. and ideally i would like to be able to set the RequestFormat from inside the OperationContract also, acording to the Content-Type header.
So, could anyone tell me how i can do it, or point me towards some examples.
chers,
Later Edit: so i don't want to have things like "format" in the UriTemplate, i just want one UriTemplate, no ResponseFormat (and no RequestFormat at some point) and the ResponseBody to be output according to the AcceptHeader
[WebHelp(Comment = "For Service testing purposes")]
[WebGet(UriTemplate = "Echo")]
[OperationContract]
public ResponseBody Echo()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须删除大部分 WCF REST 代码并自行重建。不支持开箱即用的内容类型协商。我相信入门套件有一个使用其扩展点的示例,您可能需要与他们核实。
You'll have to strip off most of the WCF REST code and rebuild it yourself. There is no support for content-type negotiation out of the box. I am lead to believe the starter kit has an example using their extensibility points, you may want to check with them.
http://damianblog.com/2008/10/31/wcf- rest-dynamic-response/ 是一个很好的起点
http://damianblog.com/2008/10/31/wcf-rest-dynamic-response/ is a good place to start