c# - HttpListener.IsSupported 在 XP SP3 上为 false

标签 c# .net httplistener

我们正在尝试在 Windows XP SP3 系统上部署一个使用 HttpListener 类的简单 C#(框架 2.0)应用程序:该应用程序在初始化时中止,因为 HttpListener.IsSupported属性为false

问题:什么原因会导致(相当)最新的 XP 系统不支持 HttpListener

可能重要的事情:

  • 用户不是其系统的管理员
  • 计算机上可能存在我不知道的安全策略(并且我不确定自己是否能够在不成为管理员的情况下进行检查)

最佳答案

好的,在幕后 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 上:

version.HttpApiMajorVersion = 2; 
version.HttpApiMinorVersion = 0;
flags = 5;
pReserved = null;

描述here 。并套bool supported = HttpInitialize(...) == 0;

您可以尝试使用PInvoke直接调用它并检查system error code返回

关于c# - HttpListener.IsSupported 在 XP SP3 上为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10026387/

相关文章:

c# - 如何在匿名委托(delegate)中调用异步方法?

c# - 是否有从字符串转换为构造函数类型的 DI 框架?

c# - 第 2 轮 : HttpListener not receiving outside requests

c# - .Net HttpListener.GetContext() 给客户端 "503 Service Unavailable"

Java Socket知道何时向gmail发出请求

c# - JSON.NET 错误检测到类型的自引用循环

c# - 这个控件叫什么?

c# - 在主线程外调用 WWW

.net - 开始一份专注于棕地应用程序重构和敏捷的新工作

c# - 如何在 C# 中旋转位图并最终得到位图?