WCF将其他HTTP标头添加到HTTP响应中以传输SOAP消息

atu*_*rch 2 c# wcf soap web-services

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

Jan*_*rta 6

我相信这篇文章是关于您想做什么的:这里。您可以执行以下操作:

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

  • 因此,消息检查器也许可以发挥神奇的作用:[link](http://weblogs.asp.net/paolopia/writing-a-wcf-message-inspector)看起来很有前途,但我从未使用过这些。 (2认同)