如何使用具有Tls 1.2的端点的Svcutil.exe获取元数据

问题描述 投票:6回答:2

有没有人知道如何使SvcUtil.exe连接到使用TLS 1.2的端点?我正在使用.Net Framework版本4.6.1。

当我使用VS 2017进行连接时,我可以看到使用Fiddler,使用使用Version: 3.3 (TLS/1.2)的ClientHello握手在隧道上建立请求。但是,当我直接使用svcutil.exe时,它尝试使用尝试使用Version: 3.1 (TLS/1.0)的ClientHello握手建立隧道的请求,然后失败。

我希望我能够在SvcUtil.exe.config中设置如下内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <generatePublisherEvidence enabled="false" />
  </runtime>
  <system.net>
    <settings>
        <servicepointmanager securityprotocol="tls12">
        </servicepointmanager>
    </settings>
  </system.net>
</configuration>

这将镜像ServicePointManager类上的等效SecurityProtocol属性。但是,这只会产生以下错误:

 Unrecognized element 'servicepointmanager'.

我使用SvcUtil如下:

SvcUtil https://myserver/myservice/mex
wcf tls1.2 svcutil.exe
2个回答
2
投票

解决方案是跟随并添加以下链接中提供的HKEY以允许通过svcutil提供仅限TLS 1.2的服务: https://blogs.msdn.microsoft.com/dsnotes/2015/09/23/wcf-ssltls-failure-during-add-service-reference-system-net-security-sslstate-processauthentication/

简而言之,解决方案如下:

  • 将以下注册表设置DWORD值添加为1并重新启动框:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SchUseStrongCrypto
  • 如果应用程序在x64窗口上运行32位,我们需要在以下位置修改相同的密钥: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\ SchUseStrongCrypto

我已经尝试添加相同的并重新启动机器,它的工作原理。


3
投票

我试图使用documentation推荐的方式,但我无法让它工作。所以我假设它使用了一些自定义配置部分。相反,我目前正在使用以下控制台应用程序来加载svcutil.exe并手动设置所需的属性:

using System.Net;
using System.Reflection;

namespace SvcUtil2
{
    class Program
    {
        static void Main(string[] args)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            // Your SvcUtil path here
            var svcUtilPath = @"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools\SvcUtil.exe";
            var svcUtilAssembly = Assembly.LoadFile(svcUtilPath);
            svcUtilAssembly.EntryPoint.Invoke(null, new object[] { args });
        }
    }
}

我知道它可能无法解答您的实际问题,但我希望它仍然有用。

© www.soinside.com 2019 - 2024. All rights reserved.