我们在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本身暴露).
Gre*_*ech 14
原来问题是操作标有...
[OperationContract(IsOneWay = true)]
Run Code Online (Sandbox Code Playgroud)
...并且单向操作中的服务器变量不可用.
羞耻的例外并没有说出那种效果......
| 归档时间: |
|
| 查看次数: |
4465 次 |
| 最近记录: |