【问题标题】:how to make a WCF Service that is only HTTP as also HTTPS without creating new or breaking existing clients如何在不创建新客户端或破坏现有客户端的情况下制作只有 HTTP 和 HTTPS 的 WCF 服务
【发布时间】:2018-11-21 11:00:16
【问题描述】:

我有一个使用 basicHttpBinding 的 WCF 服务。它以 HTTP 的形式向许多客户端公开。

现在我们的要求是将此服务作为 HTTPS 公开给少数新客户端,同时我们不应该破坏通过 http 消费的现有客户端。

我遇到了以编程方式检测安全类型然后公开的问题,但是还有其他更好更简单的方法可以做到这一点吗?只是使用端点配置等?

我对这些领域还很陌生,请帮忙举个例子

【问题讨论】:

  • 为 httpsEndpoint 创建不同的端点和行为
  • 尝试使用传输安全创建另一个端点并在 IIS 中分配一个 http 和 https 基地址。

标签: c# .net wcf https wcf-security


【解决方案1】:

是的,正如您在两天前为我们的一些服务所做的配置中提到的那样,有一个更好的解决方案。

如下添加basicHttpBinding

<basicHttpBinding>
  <binding allowCookies="true" openTimeout="00:00:10" maxReceivedMessageSize="20000000">
    <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000" />
    <security mode="None" />
  </binding>
  <binding name="secureBasicHttpBinding">
    <security mode="Transport">
      <transport clientCredentialType="None"/>
    </security>
  </binding>
</basicHttpBinding>

和服务端点:

<service  name="ServiceName">
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" bindingConfiguration="secureBasicHttpBinding" contract="your service contract">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost/Service.svc"/>
    </baseAddresses>
  </host>
</service>

在 IIS 中您只需要添加有效证书并启用它,https 使用 secureBasicHttpBindinghttp 使用默认基本 httpConfiguration

我之前已经测试过它,现在一些客户在 https 中使用该服务,而其他一些客户正在使用 http

提示:

在本地模式下,通过上述配置托管WCF 服务时出现错误,所以我得出这个结论,将该配置置于release 模式而不是debug 模式,因为https 在工作服务器上启用.

所以在release 配置中有类似的东西(发布后转移):

<service  name="ServiceName" xdt:Locator="Match(name)" xdt:Transform="Replace">
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
  <endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" bindingConfiguration="secureBasicHttpBinding" contract="your service contract">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost/AAA/Service.svc"/>
    </baseAddresses>
  </host>
</service>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多