【问题标题】:WCF HTTPS SSL Self Hosted Cert. How to Get Working Correctly?WCF HTTPS SSL 自托管证书。如何正确工作?
【发布时间】:2012-11-14 19:22:15
【问题描述】:

我正在努力使用 WCF 和注册到 IIS 的自签名证书将 silverlight 应用程序从 HTTP 转换为 HTTPS。

我在 Visual Studio 2010 命令提示符中进行的调用:

 makecert -sv SignRoot.pvk -cy authority -r signroot.cer -a
    sha1 -n "CN=Dev Certification Authority" -ss my -sr localmachine    

makecert -iv SignRoot.pvk -ic signroot.cer -cy end -pe -n
    CN="localhost" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr
    localmachine -sky exchange -sp
    "Microsoft RSA SChannel Cryptographic Provider" -sy 12

我有这个作为终点(这是在 Fiddler 中仍然不是 HTTP 的调用)

<!-- Address that the Silverlight clients will connect to -->
<!-- as specified in their web.config -->
<add key="gatewayListeningHttpURI" value="http://localhost:10201/" />

当前服务器配置:

<!-- set up binding for duplex service -->
<bindings>
  <customBinding>
    <binding name="customDuplexBinding">
      <pollingDuplex duplexMode="MultipleMessagesPerPoll"
           maxOutputDelay="00:00:01"
   serverPollTimeout="00:01:00"
   inactivityTimeout="02:00:00"
   maxPendingMessagesPerSession="2147483647"
   maxPendingSessions="2147483647" />
      <binaryMessageEncoding>
        <readerQuotas
          maxDepth="2147483647"
          maxStringContentLength="2147483647"
          maxArrayLength="2147483647"
          maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647" />
      </binaryMessageEncoding>
      <httpTransport
  maxBufferSize="2147483647"
  maxReceivedMessageSize="2147483647"
  transferMode="StreamedResponse"
            />
    </binding>
  </customBinding>

</bindings>

<behaviors>
  <endpointBehaviors>
    <!-- For Policy Service -->
    <behavior name="webHttpEndpointBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>
    <behavior name="sb">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <!-- This will solve a bug that happens if too many items are sent at once from the gateway to the client -->
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      <serviceThrottling
      maxConcurrentCalls="200"
      maxConcurrentSessions="200"
      maxConcurrentInstances="200" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<services>
  <service name="ME.Streets.WebGateway.DuplexService.DuplexService"
     behaviorConfiguration="sb">
    <endpoint
       address="basic"
       binding="customBinding"
       bindingConfiguration="customDuplexBinding"
       contract="ME.Streets.WebGateway.DuplexService.Interface.IDuplexServiceContract">
    </endpoint>
    <endpoint
        address=""
        binding="webHttpBinding"
        behaviorConfiguration="webHttpEndpointBehavior"
        contract="ME.Streets.WebGateway.DuplexService.Interface.IPolicyRetriever"/>
    <endpoint
        address="mex"
        binding="mexHttpBinding"
        contract="IMetadataExchange"/>
  </service>
</services>

当前客户端配置:

private DuplexServiceContractClient CreateDuplexServiceClient(EndpointAddress endPoint)
    {
        PollingDuplexBindingElement pollingDuplexBindingElement = new PollingDuplexBindingElement();
        pollingDuplexBindingElement.DuplexMode = PollingDuplexMode.MultipleMessagesPerPoll;

        #if DEBUG
        pollingDuplexBindingElement.ClientPollTimeout = TimeSpan.FromMinutes(15);
        pollingDuplexBindingElement.InactivityTimeout = TimeSpan.FromMinutes(14);
        #else
        pollingDuplexBindingElement.ClientPollTimeout = TimeSpan.FromMinutes(60);
        pollingDuplexBindingElement.InactivityTimeout = TimeSpan.FromMinutes(60);
        #endif

        HttpsTransportBindingElement httpsTransportBindingElement = new HttpsTransportBindingElement();
        httpsTransportBindingElement.MaxBufferSize = int.MaxValue;
        httpsTransportBindingElement.MaxReceivedMessageSize = int.MaxValue;
        httpsTransportBindingElement.TransferMode = TransferMode.StreamedResponse;

        CustomBinding binding = new CustomBinding(
            pollingDuplexBindingElement,
            new BinaryMessageEncodingBindingElement(),
        httpsTransportBindingElement);

        var dscc = new DuplexServiceContractClient(binding, endPoint);

        dscc.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(5);

#if DEBUG
        dscc.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(15);
#endif
        return dscc;
    }

我已经将我的 silverlight 应用程序部署到 IIS 中并添加了 HTTPS 协议,以便我可以通过在网址前面添加 HTTPS 来访问它。

问题仍然是当我登录 https 站点 (https://localhost/FleetNew) 时,我仍然收到“显示混合内容”的错误

当我在 fidler 中观看时,调用 localhost:10201 是不安全的 http 调用。

我的 netsh http show sslcert 命令给我带来了这个:

IP:port                 : 0.0.0.0:10201
Certificate Hash        : 0fb891e03c857d1c50b63163e5a0b999ed757ea1
Application ID          : {3d5900ae-111a-45be-96b3-d9e4606ca793}
Certificate Store Name  : (null)
Verify Client Certificate Revocation    : Enabled
Verify Revocation Using Cached Client Certificate Only    : Disabled
Usage Check    : Enabled
Revocation Freshness Time : 0
URL Retrieval Timeout   : 0
Ctl Identifier          : (null)
Ctl Store Name          : (null)
DS Mapper Usage    : Disabled
Negotiate Client Certificate    : Disabled

IP:port                 : 0.0.0.0:443
Certificate Hash        : 0fb891e03c857d1c50b63163e5a0b999ed757ea1
Application ID          : {4dc3e181-e14b-4a21-b022-59fc669b0914}
Certificate Store Name  : MY
Verify Client Certificate Revocation    : Enabled
Verify Revocation Using Cached Client Certificate Only    : Disabled
Usage Check    : Enabled
Revocation Freshness Time : 0
URL Retrieval Timeout   : 0
Ctl Identifier          : (null)
Ctl Store Name          : (null)
DS Mapper Usage    : Disabled
Negotiate Client Certificate    : Disabled

请帮我正确配置,以便对 locahost:20102 的调用可以通过 ssl 和 HTTPS 工作

【问题讨论】:

    标签: c# wcf iis ssl https


    【解决方案1】:

    据我所知,您缺少一些使用 SSL 托管 WCF 自托管服务所需的 HTTPS 元数据端点和行为配置。执行您需要的主要步骤如下:

    1. 使用与端点 URL 的域名匹配的通用名称值创建自签名证书(用于测试目的)(最好使用您的机器名称)
    2. 使用 netsh.exe 使用其指纹将端口与您的 SSL 证书绑定。
    3. 将您的 WCF .config 文件配置为具有所需的 SSL 设置。

    这是一个相当漫长的过程,因此我没有尝试在这里记录每个步骤,而是在博客文章中详细介绍了使用 SSL 获取 WCF 自托管服务所需的内容。这应该可以帮助您看到一个可行的解决方案,然后您可以将其应用于您的项目:

    Applying and Using a SSL Certificate With A Self-Hosted WCF Service

    【讨论】:

    • 我已经将 ssl 证书绑定到端口(请参阅我的问题的最后一部分),并且我的证书名为 "localhost" 。我只是非常坚持如何正确配置服务器和客户端的 WCF 配置文件以正常工作
    • 我知道看我发布的一篇大文章并尝试一下会很臭,但你真的应该通读一遍并试一试。让 SSL 为自托管服务工作花了我一段时间和研究的组合,所以您可能应该阅读整个过程。至少,将博客文章中的配置设置与您的配置设置进行比较。它主要是您需要担心的服务器端。一旦你有一个工作的 SSL 服务,客户端将不需要在添加服务引用后进行修改。
    • 在来这里之前,我实际上使用了您的博客文章。我又读了一遍,但我想我需要一些帮助
    • 再次查看您的配置后,我认为您对服务器和客户端配置感到困惑。 服务器 是您指定 SSL 并公开 HTTPS 端点的地方,而不是客户端。正如我所说,一旦您从工作的 SSL 服务添加服务引用,客户端将自动配置其绑定。但在您的服务器配置中,&lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt; 不表示 HTTPS,端点也不表示。我的帖子说整个服务配置如下:也看baseAddress。都在那里。
    • 我已经更新了我认为的当前服务器/客户端配置。我正在寻找一个错误的服务器配置区域。仍然无法正常工作,但我会在这里再试一次。您在更新后的原始帖子中发现有什么值得更改的地方吗?
    猜你喜欢
    • 2014-09-09
    • 2020-08-02
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 2022-07-01
    • 1970-01-01
    相关资源
    最近更新 更多