【问题标题】:Browse svc file over https通过 https 浏览 svc 文件
【发布时间】:2014-10-14 14:58:12
【问题描述】:

我有一个服务。我可以用 http 浏览它的 svc 文件。但是,我无法通过 https 访问它。我需要对其进行一些配置更改吗? 这是一个示例配置文件

  <?xml version="1.0"?>
  <configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.0"/>
    </system.web>

    <system.serviceModel>

      <client>
      <endpoint address="http://localhost/Sum_Wcf/Service1.svc" binding="webHttpBinding"
      behaviorConfiguration="EndPointBehavior" contract="SumServiceReference.IService1" name="WebHttpBinding_Well" />
      </client>

      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>

        <standardEndpoints>
        <webScriptEndpoint>
          <standardEndpoint name="" crossDomainScriptAccessEnabled="true">
        </standardEndpoint>
        </webScriptEndpoint>
      </standardEndpoints>

      <behaviors>
        <endpointBehaviors>
          <behavior name="EndPointBehavior">
            <enableWebScript />
          </behavior>
        </endpointBehaviors>
      </behaviors>
   </system.serviceModel>

   <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
      <directoryBrowse enabled="true"/>
    </system.webServer>

  </configuration>

这是服务器端配置文件。 客户端元素在那里,因为它是一个演示应用程序,我在同一个应用程序中也有一个客户端应用程序,用于测试目的。

【问题讨论】:

  • Google 出现了这个问题,其中包括:SSL for webHttpBinding
  • 您的 web.config 似乎与客户端配置和服务器配置混合在一起。那么配置文件是用在客户端还是服务端呢?
  • 这是一个服务器配置

标签: asp.net wcf service https config


【解决方案1】:

WCF 4.0 引入了默认端点、绑定和行为的概念。开箱即用,无需向配置文件添加任何内容,您将在 .svc 文件的位置获得一个默认端点,默认绑定为basicHttpBindingbasicHttpBinding 的默认安全模式是“无”,因此即使其他所有配置都正确,我也不希望您能够通过 SSL 浏览服务。

首先,您的配置文件。您已经定义了客户端端点 - 如果您的服务正在调用另一个服务,那么您只需要服务配置中的那些,它似乎不是。您需要的是服务端点(默认情况下您有一个,但您需要webHttpBinding,而不是basicHttpBinding

现在,如果您想坚持使用默认值(必要时使用覆盖),您可以尝试以下操作:

<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding>
        <security mode="Transport" />
      </binding>
    </webHttpBinding>
  </bindings>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true"
                             aspNetCompatibilityEnabled="true"/>
  <standardEndpoints>
    <webScriptEndpoint>
      <standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
    </webScriptEndpoint>
  </standardEndpoints>
  <behaviors>
    <endpointBehaviors>
      <behavior>
        <enableWebScript />
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <protocolMapping>
    <add binding="webHttpBinding" scheme="https" />
  </protocolMapping>

这样做是为webHttpBindng 设置默认配置(通过省略&lt;binding&gt; 元素上的name 属性)将securityMode 设置为“传输” - 这意味着任何使用该配置的服务webHttpBinding 将使用您定义的绑定配置。

这同样适用于行为 - 默认情况下,指定的配置将用于端点,因为省略了 name 属性。

最后一部分是 &lt;protocolMappings&gt; 部分 - 在这里您告诉应用程序使用 webHttpBinding 传输 https

您仍然可以像在 WCF 3/3.5 中那样显式定义端点。

我不确定(因为我没有将 SSL 与 WCF 或 webHttpBinding 一起使用),但您可能还需要证书才能这样做,但您可以尝试上述方法,看看是否可以你正朝着正确的方向前进。

还可以查看我在对您的问题的评论中链接到的article,或者查看 Google 搜索结果的链接以了解更多信息。

【讨论】:

  • 不确定配置示例是否有拼写错误或者是 IIS 中的差异,但在 Server 2012 R2、IIS 8.5.9600 上,&lt;securityMode="Transport" /&gt; 应该是 &lt;security mode="Transport" /&gt;&lt;protocolMappings&gt; 变为 @987654340 @.
  • @Aaron - 错别字。感谢您指出它们,我已修复它们。
【解决方案2】:

您需要在其中添加带有basichttpbinding标签的绑定xml标签,并在其中添加&lt;security mode="Transport"/&gt;

当然,您可以使用名称绑定所有配置,在其命名的 https 下方:

  <basicHttpBinding>
    <binding name="https">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>

【讨论】:

  • 重新阅读 OP 的问题...添加安全模式为“Transport”的basicHttpBinding 无济于事。他们正在使用webHttpBinding
  • 我需要 webHttpBinding
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多