Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF WF服务,无法为具有权限的SSL/TLS建立安全通道_C#_Wcf_Ssl_Workflow Foundation - Fatal编程技术网

C# WCF WF服务,无法为具有权限的SSL/TLS建立安全通道

C# WCF WF服务,无法为具有权限的SSL/TLS建立安全通道,c#,wcf,ssl,workflow-foundation,C#,Wcf,Ssl,Workflow Foundation,在尝试访问我的WCF WF服务时,我一直遇到相同的错误:“无法为具有权限的SSL/TLS建立安全通道。” 我已经尝试了一系列stackoverflow/google解决方案,但到目前为止运气不佳 我制作了一个WCF WF服务,它连接到使用证书进行验证的第三方。我的Web.config如下所示: <?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFri

在尝试访问我的WCF WF服务时,我一直遇到相同的错误:“无法为具有权限的SSL/TLS建立安全通道。”

我已经尝试了一系列stackoverflow/google解决方案,但到目前为止运气不佳

我制作了一个WCF WF服务,它连接到使用证书进行验证的第三方。我的Web.config如下所示:

<?xml version="1.0"?>
<configuration>
<appSettings>
  <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
  <compilation debug="true" strict="false" explicit="true" 
                            targetFramework="4.5.1"/>
  <httpRuntime targetFramework="4.5.1"/>
</system.web>
<system.serviceModel>
  <bindings>      
    <basicHttpsBinding>
      <binding name="binding1">
        <security mode="TransportWithMessageCredential">
          <message clientCredentialType="Certificate" />
        </security>
      </binding>
    </basicHttpsBinding>
  </bindings>
  <client>
    <!-- Test Endpoint -->
    <endpoint address="https://example.com" 
              behaviorConfiguration="endpointBehavior" 
              binding="basicHttpsBinding" 
              bindingConfiguration="binding1" 
              contract="ContractPortType" 
              name="Port">
    </endpoint>
  </client>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>        
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="endpointBehavior">
        <clientCredentials>          
          <clientCertificate findValue="SOMETHUMBPRINT" 
                              storeLocation="LocalMachine" 
                              storeName="My" 
                              x509FindType="FindByThumbprint" />
        </clientCredentials>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"/>
  </protocolMapping>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
                             multipleSiteBindingsEnabled="true" 
                             minFreeMemoryPercentageToActivateService="1"/>
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
具有以下App.config的:

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <system.serviceModel>
    <bindings>     
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService"/>
      </basicHttpBinding>
    </bindings>

    <client>
      <endpoint address="http://localhost:55670/GetData.xamlx"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
        contract="Reference.IService" name="BasicHttpBinding_IService" behaviorConfiguration="endpointBehavior" />
    </client>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="endpointBehavior">
          <clientCredentials>
            <clientCertificate findValue="SOMETHUMBPRINT"
                               storeLocation="LocalMachine"
                               storeName="My"
                               x509FindType="FindByThumbprint" />
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

今年早些时候,我遇到了一个类似的问题,结果证明一些SSL证书使用TLS1.2

.NET 4.5默认TLS版本为v1.1。这可以通过以下代码段在代码中更改:

using System.Net;
// ...
// In your application startup flow, set the security protocol to TLS 1.2.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
理想情况下,应在应用程序启动时调用上述内容。在那之后,我想你可以走了

旁注:.NET 4.0目标应用程序需要稍微不同的技巧来设置TLS版本:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
在.NET 3.5及更低版本中,TLS 1.2甚至不受支持。但在您的情况下,它看起来像是您的目标.NET4.5,所以您最好在这方面继续努力

编辑:我注意到在您的客户端代码片段中,您对TLS版本进行了逐位修改,这是不正确的。在本例中,它应该是单个值,
SecurityProtocolType.Tls12

我假设底层的.NET Framework网络代码最终只使用了
SecurityProtocolType.Tls
,这与SSL/Tls证书支持的内容不匹配


希望这能有所帮助。

今年早些时候,我遇到了类似的问题,结果发现一些SSL证书使用TLS 1.2

.NET 4.5默认TLS版本为v1.1。这可以通过以下代码段在代码中更改:

using System.Net;
// ...
// In your application startup flow, set the security protocol to TLS 1.2.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
理想情况下,应在应用程序启动时调用上述内容。在那之后,我想你可以走了

旁注:.NET 4.0目标应用程序需要稍微不同的技巧来设置TLS版本:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
在.NET 3.5及更低版本中,TLS 1.2甚至不受支持。但在您的情况下,它看起来像是您的目标.NET4.5,所以您最好在这方面继续努力

编辑:我注意到在您的客户端代码片段中,您对TLS版本进行了逐位修改,这是不正确的。在本例中,它应该是单个值,
SecurityProtocolType.Tls12

我假设底层的.NET Framework网络代码最终只使用了
SecurityProtocolType.Tls
,这与SSL/Tls证书支持的内容不匹配


希望这能有所帮助。

我能做到这一点的唯一方法就是使用HttpModule(感谢ajawad987的提示)。我仍然相信这只能(或应该)在Web.config中完成

public class InitializerModule : IHttpModule
{
    public void Dispose() { }

    public void Init(HttpApplication context)
    {
        // Sets the TLS version for every request made to an external party
        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    }
}
Web.config

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="InitializerModule" type="WorkflowService.Helpers.InitializerModule"/>
  </modules>
</system.webServer>

我能做到这一点的唯一方法就是使用HttpModule(感谢ajawad987的提示)。我仍然相信这只能(或应该)在Web.config中完成

public class InitializerModule : IHttpModule
{
    public void Dispose() { }

    public void Init(HttpApplication context)
    {
        // Sets the TLS version for every request made to an external party
        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    }
}
Web.config

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="InitializerModule" type="WorkflowService.Helpers.InitializerModule"/>
  </modules>
</system.webServer>


您是否尝试过使用WCF跟踪(svctraceviewer.exe)@亚尼夫,我会看看的,谢谢你的帮助tip@Yaniv使用跟踪没有任何明智之处,每个错误都是相同的“无法为具有权限的SSL/TLS建立安全通道”您是否尝试过使用WCF跟踪(svctraceviewer.exe)@亚尼夫,我会看看的,谢谢你的帮助tip@Yaniv使用跟踪并没有变得更明智,每个错误都是相同的“无法通过授权为SSL/TLS建立安全通道”,我在调用客户机时已经添加了这一点(请参阅客户机代码)。当我直接从控制台访问第三方时,它就工作了,但是当我从工作流服务调用第三方时,我得到了这个错误。我找不到在WCF WF服务中设置安全协议的方法。我应该更彻底地阅读你的帖子。我还没有找到一种方法,但是也许您可以使用一个http模块来设置适当的TLS级别。它将在您的WCF服务之前被调用。或者实际创建一个设置它的服务行为。我在调用客户机时已经添加了这个(请参阅客户机代码)。当我直接从控制台访问第三方时,它就工作了,但是当我从工作流服务调用第三方时,我得到了这个错误。我找不到在WCF WF服务中设置安全协议的方法。我应该更彻底地阅读你的帖子。我还没有找到一种方法,但是也许您可以使用一个http模块来设置适当的TLS级别。它将在您的WCF服务之前被调用。或者实际创建设置它的服务行为。