HttpContext.Current在我的Web服务中为null [英] HttpContext.Current is null in my web service
本文介绍了HttpContext.Current在我的Web服务中为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Web服务(.svc),我试图使用StackOverflow上其他地方找到的一段代码捕获SOAP请求.
I have a web service (.svc), and I am trying to capture the SOAP request using a piece of code found elsewhere on StackOverflow.
问题是HttpContext.Current
为空,所以我无法访问Request.InputString
.
The problem is that HttpContext.Current
is null, so I can't access Request.InputString
.
为什么它为null,如何解决?
Why is this null, and how can it be solved?
XmlDocument xmlSoapRequest = new XmlDocument();
Stream receiveStream = HttpContext.Current.Request.InputStream;
receiveStream.Position = 0;
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
xmlSoapRequest.Load(readStream);
}
推荐答案
如果您要使用HttpContext
,因为代码已经这样编写;您需要将其添加到服务所在的web.config中:
If you want to use HttpContext
because the code has already been written as so; you need to add this to your web.config where your service resides:
<configuration>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
</configuration>
这篇关于HttpContext.Current在我的Web服务中为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文