【问题标题】:WCF Exception: Could not find a base address that matches scheme http for the endpointWCF 异常:找不到与端点的方案 http 匹配的基地址
【发布时间】:2013-11-23 22:54:54
【问题描述】:

我正在尝试在 IIS 中的单独网站上托管 WCF Web 服务,并将 443 处的 https 作为唯一绑定。

当我在同时使用两种绑定 (http(80) / https(443)) 的网站中使用以下配置时,它运行良好。如果我删除 http 绑定,它会开始抛出以下错误。

找不到与绑定 BasicHttpBinding 的端点的方案 http 匹配的基地址。注册的基地址方案是 [https]。

如何使其在仅使用 https 绑定的 IIS 网站中工作?

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="defaultBasicHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="Certificate" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/ERPService/retailPayment.svc"
                binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding"
                contract="RetailPaymentService.RetailPayment.SVRetailPaymentService" name="EnterpriseRetailPayment" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="MyEndPointBehavior">
          <!--<SchemaValidator enabled="true"/>-->
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="SettlementSalesCollection.SaleItemService" behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint behaviorConfiguration="MyEndPointBehavior" binding="basicHttpBinding"
                  name="SettlementSalesCollection"
                  contract="SettlementSalesCollection.CITransactionSettlementListenerService" />
        <endpoint name="mexEndpoint" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>
    </services>
    <extensions>
      <behaviorExtensions>
        <add name="SchemaValidator"
             type="SettlementSalesCollection.SchemaValidation.SchemaValidationBehavior+CustomBehaviorSection, SettlementSalesCollectionService, Version=1.0.0.0, Culture=neutral" />
      </behaviorExtensions>
    </extensions>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

【问题讨论】:

  • 将您的客户端端点更改为 https?例如endpoint address="https://localhost/ERPService/retailPayment.svc
  • 那是这个服务使用的另一个服务。它以 http 运行。我刚刚发布了完整的 配置部分
  • 也许将&lt;add binding="basicHttpBinding" scheme="http" /&gt; 添加到&lt;protocolMapping&gt; 部分?这是 WCF 的默认设置(所以它应该存在,除非你从另一个配置文件继承),但它可能值得一试。

标签: c# wcf web-services


【解决方案1】:

您的配置应该与此类似。您可能需要根据您的身份验证需要更改&lt;transport clientCredentialType="None" proxyCredentialType="None" /&gt;。下面的配置不需要任何身份验证。

<bindings>
    <basicHttpBinding>
        <binding name="basicHttpBindingConfiguration">
            <security mode="Transport">
                <transport clientCredentialType="None" proxyCredentialType="None" />
            </security>
        </binding>       
    </basicHttpBinding>
</bindings>

<services>
    <service name="XXX">
        <endpoint
            name="AAA"
            address=""
            binding="basicHttpBinding"
            bindingConfiguration="basicHttpBindingConfiguration"
            contract="YourContract" />
    </service>
<services>

这将允许带有basicHttpBinding 的 WCF 服务使用 HTTPS。

【讨论】:

    【解决方案2】:

    在我的情况下,这解决了问题

    1. 在项目名称上单击 F4 转到项目属性
    2. 设置 SSLEnabled = true

    Project Properties Image

    【讨论】:

      【解决方案3】:

      我的问题是由于 IIS 中缺少绑定引起的,在左侧树视图“连接”中,在站点下,右键单击您的站点 > 编辑绑定 > 添加 > https

      选择“IIS Express 开发证书”并将端口设置为 443 然后我在 webconfig 中添加了另一个绑定:

      &lt;endpoint address="wsHttps" binding="wsHttpBinding" bindingConfiguration="DefaultWsHttpBinding" name="Your.bindingname" contract="Your.contract" /&gt;

      还添加到 serviceBehaviours: &lt;serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" /&gt;

      最终它奏效了,我在 stackoverflow 上检查的这个错误的解决方案都不适用于我的特定场景,所以包括这里以防它帮助其他人

      【讨论】:

      • 这是我遇到的问题。我的配置同时具有 HTTP 和 HTTPS 的绑定。我发现默认 IIS 网站不包含 HTTPS 绑定。如果您的配置具有 HTTP 和 HTTPS 的端点,则需要添加它。
      【解决方案4】:

      如果您仅将https 配置为 IIS 内的站点绑定,则可以得到此信息。

      您需要添加http(80)https(443) - 至少我做到了:-)

      【讨论】:

      • (右键网站选择Edit Bindings)
      • 刚刚意识到我的答案并不是真正的答案,因为提问者特别想避免这样做 - 但我会留下它,因为它似乎有助于一些必须通过以下方式找到这个问题的人错误消息。
      • 这对我有用
      【解决方案5】:

      我根据@Szymon 的回答尝试了绑定,但它对我不起作用。我尝试了 basicHttpsBinding 这是 .net 4.5 中的新功能,它解决了这个问题。这是适合我的完整配置。

      <system.serviceModel>
          <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
          <behaviors>
            <serviceBehaviors>
              <behavior>
                <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
              </behavior>
            </serviceBehaviors>
          </behaviors>
          <bindings>
            <basicHttpsBinding>
              <binding name="basicHttpsBindingForYourService">
                <security mode="Transport">
                  <transport clientCredentialType="None" proxyCredentialType="None"/>
                </security>
              </binding>
            </basicHttpsBinding>
          </bindings>
          <services>
            <service name="YourServiceName">
              <endpoint address="" binding="basicHttpsBinding" bindingName="basicHttpsBindingForYourService" contract="YourContract" />
            </service>
          </services>   
      </system.serviceModel>
      

      仅供参考:我的应用程序的目标框架是 4.5.1。我为部署此 wcf 服务而创建的 IIS 网站仅启用了 https 绑定。

      【讨论】:

      • 这对我有用。重要的是还要确保 httpRuntime 中的 targetFramework 已相应设置,即
      【解决方案6】:

      在我的情况下,协议映射下的绑定名称与端点上的绑定名称不匹配。它们在下面的示例中匹配。

      <endpoint address="" binding="basicHttpsBinding" contract="serviceName" />
      

          <protocolMapping>
              <add binding="basicHttpsBinding" scheme="https" />
          </protocolMapping>    
      

      【讨论】:

        【解决方案7】:

        我的问题也是由于 IIS 中缺少 https 绑定引起的: 选定的默认网站 > 在最右侧窗格中选择绑定 > 添加 > https

        选择“IIS Express 开发证书”并将端口设置为 443

        【讨论】:

          【解决方案8】:

          打开 IIS 并右键单击默认应用程序池并添加绑定以使应用程序使用 HTTPS 协议。

          类型:https

          IP 地址:全部未分配

          端口号:443

          SSL 证书:WMSVC

          然后

          点击并重启 IIS

          完成

          【讨论】:

            【解决方案9】:

            我收到了同样的错误 修复它:

            customBinding --> 绑定 --> httpTransport 更改为 httpsTransport

            binding="mexHttpBinding" 更改为 binding="mexHttpsBinding"

            对于 binding="wsHttpBinding" 添加 bindingConfiguration="_WsHttpBinding" 在 system.serviceModel --> bindings 下添加以下部分:

             <wsHttpBinding>
                  <binding name="_WsHttpBinding">
                    <security mode="Transport">
                        <transport clientCredentialType="None"/>
                    </security>            
                  </binding>
             </wsHttpBinding>
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-10-14
              • 2020-06-02
              • 1970-01-01
              • 2011-03-11
              • 1970-01-01
              相关资源
              最近更新 更多