根据 Accept 标头在函数内部设置响应格式,而不是在 REST 中使用 ResponseFormat = WebMessageFormat.Json 在外部设置响应格式

发布于 2024-08-10 17:42:09 字数 604 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无法回应 2024-08-17 17:42:09

您必须删除大部分 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文