惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
罗磊的独立博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
T
Tailwind CSS Blog
美团技术团队
Y
Y Combinator Blog
I
InfoQ
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
爱范儿
爱范儿
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
S
Security Affairs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
H
Heimdal Security Blog
博客园 - 司徒正美
Latest news
Latest news
H
Hacker News: Front Page
H
Help Net Security
Know Your Adversary
Know Your Adversary
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Secure Thoughts
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
The Cloudflare Blog
I
Intezer
N
News and Events Feed by Topic

博客园 - 風語者·疾風

转载:ZooKeeper Programmer's Guide(中文翻译) Python【map、reduce、filter】内置函数使用说明(转载) Python使用基础 Redis Sentinel:集群Failover解决方案(转载) Sentinel-Redis高可用方案(二):主从切换 Sentinel-Redis高可用方案(一):主从复制 照片方案 8天学通MongoDB(实际操作版)——第九天 构建学习型部署环境 8天学通MongoDB(实际操作版)——第一天 基础入门 构建Ubuntu Server试验环境 单元测试培训系列:(二)单元测试与Visual Studio My Record Series: (1.3) Windows Phone 7 Application Events My Record Series: (1.2) Windows Phone 7 Launchers and Choosers My Record Series: (1.1) Windows Phone 7.1 Development Environment 结合测试驱动TDD实施单元测试UnitTest 架构评审表(Architecture & Design Review Check List) 单元测试培训系列:(三)可测试性(Testability)与重构Refactoring 单元测试培训系列:(一)单元测试概念以及必要性 .NET Mocking Framework对比
Ajax-Enabled WCF Service中如何获取到Response
風語者·疾風 · 2010-08-27 · via 博客园 - 風語者·疾風

最近在研究基于Ajax-Enabled WCF方式直接给前台提供服务,在返回数据优化方面遇到一些小麻烦,归纳如下:

问题1:因为想要WCF Service方法直接返回Stream流,但若直接返回流,会被浏览器识别为文件流,弹出下载提示;

问题2:如果采用Gzip压缩Json数据流,则需要修改返回的Response中的Content-Encoding属性,否则浏览器会把流识别为乱码。

解决办法:WebOperationContext类!

在WCF中无法从HttpContext.Current中获取到当前的请求的Request和Response对象,因此必须改用WebOperationContext(PS,此类也只能在ASP.NET兼容模式的WCF中获取到上下文,普通的WCF需要使用OperationContext)以下代码分别解决问题1和问题2:
WebOperationContext
.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
WebOperationContext
.Current.OutgoingResponse.Headers.Add("Content-Encoding""gzip");