我有一个在 Windows 服务上自托管的 WCF 服务。目前它通过 http 运行,但我需要将其更改为 https。我对 .config 文件进行了一些更改。服务启动,但似乎没有侦听任何端点端口。我正在发布 .config 文件。我创建了一个自签名 SSL 证书,但我不知道它是否正确绑定到端口。我如何检查?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="TEST" type="System.Configuration.SingleTagSectionHandler"/>
</configSections>
<system.serviceModel>
<diagnostics performanceCounters="Default">
<messageLogging logEntireMessage="false" logMessagesAtServiceLevel="true" />
<endToEndTracing activityTracing="true" />
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="default" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="extern" name="Eps.EDN.Extern">
<endpoint address="https://127.0.0.1:6080" binding="basicHttpBinding"
bindingConfiguration="default" name="EpExtern" bindingNamespace="https://csatest.com.ar/Extern"
contract="Test.EDN.IExtern" />
</service>
<service behaviorConfiguration="default" name="Eps.EDN.EpsInternal">
<endpoint address="https://127.0.0.1:6090" binding="basicHttpBinding"
bindingConfiguration="default" name="EpCommon" bindingNamespace="https://csatest.com.ar/EpsInternal"
contract="Test.EDN.ICommon" />
<endpoint address="https://127.0.0.1:6091" binding="basicHttpBinding"
bindingConfiguration="default" name="EpUserManagement" bindingNamespace="https://csatest.com.ar/EpsInternal"
contract="Test.EDN.IUserManagement" />
<endpoint address="https://127.0.0.1:6092" binding="basicHttpBinding"
bindingConfiguration="default" name="EpConfiguration" bindingNamespace="https://csatest.com.ar/EpsInternal"
contract="Test.EDN.IConfiguration" />
<endpoint address="https://127.0.0.1:6093" binding="basicHttpBinding"
bindingConfiguration="default" name="EpMeterManagement" bindingNamespace="https://csatest.com.ar/EpsInternal"
contract="Test.EDN.IMeterManagement" />
<endpoint address="https://127.0.0.1:6094" binding="basicHttpBinding"
bindingConfiguration="default" name="EpCustomerManagement" bindingNamespace="https://csatest.com.ar/EpsInternal"
contract="Test.EDN.ICustomerManagement" />
<endpoint address="https://127.0.0.1:6095" binding="basicHttpBinding"
bindingConfiguration="default" name="EpVending" bindingNamespace="https://csatest.com.ar/EpsInternal"
contract="Test.EDN.IVending" />
</service>
<service behaviorConfiguration="report" name="Test.EDN.Reporting.ReportEngine">
<endpoint address="https://127.0.0.1:6096" binding="basicHttpBinding"
bindingConfiguration="default" name="EpReportEngine" bindingNamespace="https://csatest.com.ar/ReportEngine"
contract="Test.EDN.Reporting.IReportEngine" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="default">
<serviceMetadata httpsGetEnabled="true"
httpsGetUrl="https://127.0.0.1:6100" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="report">
<serviceMetadata httpsGetEnabled="true"
httpsGetUrl="https://127.0.0.1:6101" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="extern">
<serviceMetadata httpsGetEnabled="true"
httpsGetUrl="https://127.0.0.1:6102" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
<add name="TEST" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(FAILOVER_MODE=(TYPE=select)(METHOD=basic))(SERVER=dedicated)(SERVICE_NAME=XE)));Pooling=True;Connection Timeout=60;Min Pool Size=10;"></add>
</connectionStrings>
<appSettings>
<add key="MaxRecs" value="30"> </add>
<add key="00" value="TestService.EDN.DLL,Eps.EDN.EpsInternal"> </add>
<add key="01" value="TestService.EDN.ReportEngine.DLL,Eps.EDN.Reporting.ReportEngine"> </add>
<add key="02" value="TestService.EDN.External.DLL,Eps.EDN.Extern"> </add>
</appSettings>
<TEST key="2FDB0B5D15CF7076576E0F1B2DB1D986" ID="1"/>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
´´
根据您的配置代码,我建议如下:
1.您提到需要进行证书身份验证,但在您的代码中:
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
我认为这不会启用证书身份验证,您需要像我一样修改代码:
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
同时继续补充:
<clientCredentials>
<!-- Specify the client certificate -->
<clientCertificate storeLocation="LocalMachine"
storeName="Root"
findValue="TestCertificateSubjectName"
x509FindType="FindBySubjectName"/>
</clientCredentials>
以上是我创建的基于测试的本地证书。
最后,我还推荐使用wshttpbinding。在某些情况下,使用 basichttpbinding 会导致错误。