html - 返回 iCal 的 WCF 服务

标签 html wcf format response

如何让使用 WCF 编写的服务返回 iCal?我看到的示例使用 xml 或 json 作为格式化响应的方式。返回其他类型响应主体的最佳方式是什么?

最佳答案

像这样:

[WebGet(UriTemplate="{id}.ics")]
[OperationContract]
Stream GetCalendar(int id)
{
   WebOperationContext.Current.OutgoingResponse.ContentType="text/calendar";

   //Now just return the appropriate data in iCal format in the Stream...
}

所以现在您可以执行 HTTP GET 到例如yourService.svc/123.ics 并取回 iCal。

这样做的原因是“Stream”在 WCF REST 中是特殊的(用于非 XML、非 JSON 响应)。

请记住,您必须同时使用 WebHttpBinding 和 WebHttp 行为才能使其工作。

关于html - 返回 iCal 的 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1521802/

相关文章:

javascript - 如果动态输入,如何获取javascript中所有输入值的总计

html - 如何创建具有重复图像的固定页脚

.net - 从 WCF 服务生成单独的 "model"类

r - R 中带前导加号的格式

javascript - 如果 CSS 中存在超过 3 个元素,如何在新行中自动格式化?

html - chrome 移动版 VS chrome 桌面版 : different position of the same element

javascript - 无法调用函数

c# - WCF 双工服务使用 net tcp : "Stream Security is required..."

wcf - 间歇性WCF连接(没有端点..)错误

php - 从 php 日期获取日期格式如 "Y-m-d H:i:s"