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

标签 wcf tls1.2 svcutil.exe

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

当我使用 VS 2017 连接时,我可以看到使用 Fiddler 请求是通过使用 ClientHello 握手的隧道建立的,该握手使用 Version: 3.3 (TLS/1.2) .但是,当我直接使用 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>

这将反射(reflect)等效的 SecurityProtocol ServicePointManager 类上的属性。但是,这只会产生以下错误:
 Unrecognized element 'servicepointmanager'.

我使用 SvcUtil 如下:
SvcUtil https://myserver/myservice/mex

最佳答案

我尝试使用 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 });
        }
    }
}

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

关于wcf - 如何使用带有 Tls 1.2 的端点的 Svcutil.exe 获取元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46707472/

相关文章:

java - 从 Java 代码连接 TLS

java - SSL/TLS 动态 key 生成

c# - WCF "Always generate message contracts"不生成 MessageContract

c# - 如何在 ChannelFactory<TChannel>.Faulted 中获取故障详细信息

c# - 创建没有配置文件的 WCF 客户端

java - SSL 握手异常 : Received fatal alert: handshake_failure ( ignores ciphers)

c# - 通过 WCF 提供类对象的数组或列表

.net - 从 .NET DLL 使用 webservice - app.config 问题

c# - gzip 流并使用 WCF 发送它

wcf - 我什么时候应该在 WCF 中使用数据契约(Contract)以及什么时候使用消息契约(Contract)