我的应用程序连接到两个 WCF 服务。一种是较旧的 http 协议。另一个是较新的和 https。到现在为止他们都玩得很好。
但是,我现在发现我的旧服务被 BitDefender 和其他端点保护阻止,因为它是 http。因此,我试图让旧服务使用 https,但保持向后兼容仍使用 http 的之前补丁级别。所以我所做的就是将旧服务器(我将其称为 Walrus)转换为同时监听 http 和 https。旧服务和新服务均采用 .NET 编码并在同一台计算机上的 IIS 10 上运行,但侦听不同的 URL。
但是,当我安装旧服务的配置以侦听 https 时,较新的服务会中断,并显示以下消息:
There was no endpoint listening at https://cloudbackups.mycompany.net/cumulus.svc/cumulus.svc/PCBA that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
内部异常消息如下:
The remote server returned an error: (404) Not Found.
如果我恢复到之前的配置,就没有问题了。我很困惑。
旧版 WCF 的 Web.config:
<?xml version="1.0"?>
<configuration>
<!-- Services Configuration over HTTP and HTTPS -->
<connectionStrings configSource="connectionstrings.config"/>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5" />
</system.Web>
-->
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.7.2"/>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="Basic">
<security mode="None" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WsPBinder">
<security mode="None" />
</binding>
</wsHttpBinding>
<sslbinding>
<binding name="HttpsBinding">
<security mode="Transport" />
</binding>
</sslbinding>
<wssecurebinding>
<binding name="wsHttpsBinding">
<security mode="Transport" />
</binding>
</wssecurebinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="PedFastRemoteServices.PedFastRemoteServices">
<endpoint address="http://services.mycompany.net/Walrus.svc/BA"
binding="basicHttpBinding"
bindingConfiguration="Basic"
contract="Walrus.PTRemote"/>
<endpoint address="https://services.mycompany.net/Walrus.svc/BA"
binding="basicHttpBinding"
bindingConfiguration="sslbinding"
contract="Walrus.PTRemote"/>
</service>
</services>
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
以及较新 WCF 的服务器配置:
<?xml version="1.0" encoding="utf-8"?>
<!-- PedGuard Configuration over HTTPS -->
<configuration>
<connectionStrings configSource="connectionStrings.config" />
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="Basic" />
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="PTBackupServices.PedFastBackup">
<endpoint address="/cumulus.svc/PCBA"
binding="basicHttpBinding"
bindingConfiguration="Basic"
name="PCBA"
contract="cumulus.iPTPEDBackup" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>
<!--ProjectGuid: D9EFA79D-236B-4FAA-9C45-B7A61C485DF5-->
最后是客户端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BA" />
<binding name="PCBA">
<security mode="Transport" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WsPlain" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://services.mycompany.net/Walrus.svc/BA"
binding="basicHttpBinding" bindingConfiguration="BA" contract="Walrus.PTRemote"
name="BA" />
<endpoint address="http://services.mycompany.net/Walrus.svc/WsPlain"
binding="wsHttpBinding" bindingConfiguration="WsPlain" contract="Walrus.PTRemote"
name="WsPlain">
<identity>
<servicePrincipalName value="host/PF2WebMaster" />
</identity>
</endpoint>
<endpoint address="https://CloudBackups.mycompany.net/cumulus.svc/cumulus.svc/PCBA"
binding="basicHttpBinding" bindingConfiguration="PCBA" contract="cumulus.iPTPEDBackup"
name="PCBA" />
</client>
</system.serviceModel>
由于是404错误,所以很容易检查问题。
请检查为什么网址中有两个
cumulus.svc
。
并确保以下网址在您的本地有效。
https://cloudbackups.mycompany.net/cumulus.svc/PCBA