You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置WCF服务同时监听HTTP/HTTPS致新服务异常的问题

WCF服务配置冲突导致新版HTTPS服务404错误问题

问题背景

我有两个供应用程序连接的WCF服务:旧版HTTP协议服务(Walrus)和新版HTTPS协议服务(Cumulus),此前运行正常。因旧版HTTP服务被BitDefender等端点防护软件拦截,我尝试将Walrus配置为同时监听HTTP和HTTPS,以兼容旧客户端。两个服务基于.NET开发,部署在同一台IIS 10服务器,监听不同URL。

但修改Walrus配置后,新版Cumulus服务出现异常,恢复旧配置后问题消失。

错误信息

主错误:

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.

相关配置文件

旧版Walrus服务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>

新版Cumulus服务Web.config

<?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>

问题分析与解决方案

核心问题

  1. 客户端地址重复:Cumulus服务的客户端地址出现重复的cumulus.svc,导致请求地址无效,触发404错误。
  2. Walrus服务配置错误:使用绝对地址配置端点,干扰了同一服务器上其他服务的地址解析;同时使用了非标准的WCF绑定类型,导致配置解析异常。

修正步骤

1. 修正Walrus服务Web.config配置

替换system.serviceModel节点内容为标准相对地址+正确绑定配置:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>
            <!-- HTTP绑定 -->
            <binding name="BasicHttpBinding">
                <security mode="None" />
            </binding>
            <!-- HTTPS绑定 -->
            <binding name="BasicHttpsBinding">
                <security mode="Transport" />
            </binding>
        </basicHttpBinding>
        <wsHttpBinding>
            <!-- HTTP绑定 -->
            <binding name="WsHttpBinding">
                <security mode="None" />
            </binding>
            <!-- HTTPS绑定 -->
            <binding name="WsHttpsBinding">
                <security mode="Transport" />
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="ServiceBehavior" name="PedFastRemoteServices.PedFastRemoteServices">
            <!-- 使用相对地址 -->
            <endpoint address="/BA" 
                      binding="basicHttpBinding" 
                      bindingConfiguration="BasicHttpBinding" 
                      contract="Walrus.PTRemote"/>
            <endpoint address="/BA" 
                      binding="basicHttpBinding" 
                      bindingConfiguration="BasicHttpsBinding" 
                      contract="Walrus.PTRemote"/>
            <!-- wsHttpBinding端点(如需) -->
            <endpoint address="/WsPlain" 
                      binding="wsHttpBinding" 
                      bindingConfiguration="WsHttpBinding" 
                      contract="Walrus.PTRemote"/>
            <endpoint address="/WsPlain" 
                      binding="wsHttpBinding" 
                      bindingConfiguration="WsHttpsBinding" 
                      contract="Walrus.PTRemote"/>
        </service>
    </services>
</system.serviceModel>

2. 修正客户端Cumulus服务地址

将客户端配置中的Cumulus端点地址改为正确路径:

<endpoint address="https://CloudBackups.mycompany.net/cumulus.svc/PCBA"
          binding="basicHttpBinding" 
          bindingConfiguration="PCBA" 
          contract="cumulus.iPTPEDBackup"
          name="PCBA" />

3. 验证IIS站点绑定

  • 确保Walrus站点同时绑定HTTP和HTTPS端口,HTTPS绑定配置正确的SSL证书
  • 确认Cumulus站点仅绑定HTTPS端口,证书配置无误

4. 重启IIS服务

执行iisreset命令重启IIS,使所有配置修改生效

内容的提问来源于stack exchange,提问作者John Tamburo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 02:07:05