关于如何允许自托管WCF应用程序使用Basic.SttpBinding与HTTP.SYS而不需要管理权限,有几个 问题.它归结为需要向URL授予权限(从管理上下文),然后用户可以在指定的URL上托管任何内容.
netsh http add urlacl url = http:// +:80/MyService
我希望能够查询和添加注册的URL,而无需解析"netsh"或"httpconfig"命令行工具的命令行输出.
是否有可以调用此功能的公共Win32或.NET API?
我在网上看到了一些文章,描述了如何在 Windows 服务应用程序中自行托管 ASP.NET Web API(请参阅此处和此处)。我在 VB.NET 中编写了一些简单的代码,以便在服务启动时启动自主机,并在服务停止时停止它,如下所示:
Protected Overrides Sub OnStart(ByVal args() As String)
Try
' init a new self host configuration using the base address
_config = New HttpSelfHostConfiguration(New Uri("http://localhost:8080"))
' map the URLs into the config
MapRoutes(_config)
_server = New HttpSelfHostServer(_config)
' start the server and wait for requests
_server.OpenAsync()
Catch ex As Exception
Throw
End Try
End Sub
Protected Overrides Sub OnStop()
Try
_server.CloseAsync().Wait()
_server.Dispose()
Catch ex As Exception
Throw
End Try …Run Code Online (Sandbox Code Playgroud)