gpt4 book ai didi

c# - Windows 服务通过 HTTPS 托管 WCF

转载 作者:IT王子 更新时间:2023-10-29 04:43:26 26 4
gpt4 key购买 nike

我已经根据 these instructions 创建并配置了一个 SSL 证书来自MSDN。我收到错误消息 this question列表,但不确定如何将该问题中接受的答案映射到我的 App.config 文件。配置文件的内容和服务本身在 http 上正常工作,只是在 https 上出现问题。

我的 App.config 文件当前是:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="LookupServiceHost" behaviorConfiguration="serviceBehaviour">
<host>
<baseAddresses>
<add baseAddress="https://localhost:54321/MyService"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="ILookupService" bindingConfiguration="TransportSecurity" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehaviour">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

Windows 事件日志中返回的错误异常:

Service cannot be started. System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:54321/MyService/. Another application has already registered this URL with HTTP.SYS. ---> System.Net.HttpListenerException: Failed to listen on prefix 'https://+:54321/MyService/' because it conflicts with an existing registration on the machine.

有人可以指导我如何启用此功能吗?

最佳答案

我认为您正在连接两个不同的设置。 Netsh 可用于为 SSL 添加证书,但也允许应用程序在给定端口上监听而无需在管理员帐户下运行。该异常针对第二个设置。我以前没见过它,但我假设你已经为 HTTP 注册了这个端口,所以让我们尝试在另一个端口上使用(并注册)HTTPS 或替换以前的注册。

编辑:

使用提升的权限(作为管理员)打开命令提示符。首先检查 SSL 证书是否分配给了正确的端口:

netsh http show sslcert

然后通过调用检查是否在该端口上注册了 HTTP 监听:

netsh http show urlacl 

如果是这样,请使用以下命令删除该注册:

netsh http delete urlacl url=http://+:54321/MyService

再次添加注册支持监听HTTPS:

netsh http add urlacl url=https://+:54321/MyService user=domain\userName

其中用户是用于运行 Windows 服务的帐户。如果是本地帐户,则仅使用用户名。

注意:在 https 下,似乎必须在 urlacl 中使用通配符。我们不能编写 https://localhost:8733/... 来匹配 Visual Studios 默认的 http urlacl。这可能是有道理的,因为请求的主机名在解密后才可用。

关于c# - Windows 服务通过 HTTPS 托管 WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3688342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com