WCF 向 HTTP 响应添加额外的 HTTP 标头以传输 SOAP 消息 [英] WCF adding additional HTTP header to HTTP response for transporting SOAP message

查看:40
本文介绍了WCF 向 HTTP 响应添加额外的 HTTP 标头以传输 SOAP 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有 SOAP 消息架构的 WCF.我的服务使用 BasicHttpBinding 来传输我的 SOAP 消息.我需要向 HTTP 响应添加 2 个不同的 HTTP 标头(源和缓存控制).我知道在启用 aspNetCompatibilityEnabled 的情况下我可以在 Global.asax 文件中执行此操作,但是有一个问题 - 我使用 Windows 服务来托管我的 WCF.aspNetCompatibilityEnabled 仅适用于 IIS.有人可以帮我解决方法吗?

I'm working with WCF with SOAP message architecture. My services are using BasicHttpBinding for transporting my SOAP messages. I need to add 2 different HTTP headers(Origin and Cache control) to HTTP response. I know that I can do that in Global.asax file in case of enabling aspNetCompatibilityEnabled, but there is a problem - I'm using windows service for hosting my WCF. aspNetCompatibilityEnabled works only under IIS. Can anybody help me with approach?

推荐答案

我相信这篇文章是关于你想做的事情:这里.你可以这样做:

I believe this article is about what you want to do: here. You can do something like this:

var context = WebOperationContext.Current;
HttpResponseHeader cacheHeader = HttpResponseHeader.CacheControl;
String cacheControlValue = String.Format("max-age={0}, must-revalidate", maxCacheAge);
context.OutgoingResponse.Headers.Add(cacheHeader, cacheControlValue);

这篇关于WCF 向 HTTP 响应添加额外的 HTTP 标头以传输 SOAP 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆