wcf – HttpContext.Current在我的Web服务中为空
发布时间:2020-12-14 21:38:59 所属栏目:资源 来源:网络整理
导读:我有一个Web服务(.svc),我试图使用StackOverflow上其他地方找到的一段代码来捕获SOAP请求。 问题是HttpContext.Current是null,所以我无法访问Request.InputString。 为什么这是null,如何解决? XmlDocument xmlSoapRequest = new XmlDocument();Stream re
我有一个Web服务(.svc),我试图使用StackOverflow上其他地方找到的一段代码来捕获SOAP请求。
问题是HttpContext.Current是null,所以我无法访问Request.InputString。 为什么这是null,如何解决? 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中:
<configuration> <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> </system.serviceModel> </configuration> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |