相关疑难解决方法(0)

HttpRequest.ServerVariables在带有IIS7的WCF中抛出ArgumentException

我们在IIS7中运行了一个WCF(.NET 3.5 SP1)服务,该服务被标记为允许ASP.NET兼容模式,因此我们可以访问HttpContext.Current:

[AspNetCompatibilityRequirements(
    RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Run Code Online (Sandbox Code Playgroud)

但是,当尝试访问任何服务器变量时,它会抛出ArgumentException:

System.ArgumentException: Value does not fall within the expected range. 
    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) 
    at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) 
    at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name) 
    at System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress() 
    at System.Web.HttpRequest.get_UserHostAddress() 
Run Code Online (Sandbox Code Playgroud)

例如,以下任何行都会抛出此异常:

ha = HttpContext.Current.Request.UserHostAddress;
ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
us = HttpContext.Current.Request.UserAgent;
Run Code Online (Sandbox Code Playgroud)

这似乎是内部框架调用的结果,这意味着调用代码没有错.

据推测,我们的配置中有一些东西导致了这个问题,但我不知道是什么.有任何想法吗?或者任何想法我如何能够检索这三位数据(遗憾的是,它们似乎没有被WCF本身暴露).

wcf

5
推荐指数
1
解决办法
4465
查看次数

标签 统计

wcf ×1