XP SP3上的HttpListener.IsSupported为false
问题描述:
我们正试图部署一个简单的C#(框架2.0)应用程序,该应用程序在Windows XP SP3系统上使用HttpListener
类:应用程序在初始化时中止,因为HttpListener.IsSupported
属性为false
。XP SP3上的HttpListener.IsSupported为false
问:什么可以让HttpListener
不支持的一个(合理的)上的最新XP系统上?
事情会重要:
- 用户不是管理员将其系统上
- 有可能是在计算机上的安全政策,我不知道(和它的我不知道我能够检查而不被管理员自己)
答
好吧,引擎盖下HttpListener
类调用
[StructLayout(LayoutKind.Sequential)]
internal struct HTTPAPI_VERSION
{
internal ushort HttpApiMajorVersion;
internal ushort HttpApiMinorVersion;
}
[DllImport("httpapi.dll", CallingConvention=CallingConvention.StdCall, SetLastError=true, ExactSpelling=true)]
internal static extern unsafe uint HttpInitialize(HTTPAPI_VERSION version, uint flags, void* pReserved);
在XP:这是描述here
version.HttpApiMajorVersion = 2;
version.HttpApiMinorVersion = 0;
flags = 5;
pReserved = null;
。并设置bool supported = HttpInitialize(...) == 0;
您可以尝试直接调用它使用的PInvoke和检查system error code回到
答
一种可能性:XP嵌入式似乎并不能够支持HttpListener/HTTP.SYS即使SP2及更高版本。