配置 winform 应用程序以使用 windows 身份验证调用 SOAP https

Configuring winform app to call SOAP https with windows autentication

我有一个正在尝试使用的 SOAP,但我遇到了下一个问题,我在类似问题中找不到解决方案:
必须通过 HTTPS 和 Windows 凭据调用 SOAP。

我在应用程序配置中尝试做的是接下来的事情:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpsBinding>
        <binding name="WebServiceSoap">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="Windows" />
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </basicHttpsBinding>
    </bindings>
    <client>
      <endpoint address="https://someapp/SDK/WebService.asmx"
        binding="basicHttpsBinding" bindingConfiguration="WebServiceSoap"
        contract="someapp_contract.WebServiceSoap" name="WebServiceSoap" />
    </client>
  </system.serviceModel>
</configuration>

我得到的错误是:

The username is not provided. Specify username in ClientCredentials.And the error 

我也用 basicHttpBinding 尝试了不同的配置 和

<security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />

但是我得到的错误是(这是一个非常合乎逻辑的错误):

provided URI scheme 'https' is invalid; expected 'http'...

过去有人遇到过同样的问题吗?

提前致谢。
最大值

P.S:
如果我这样做

<security mode="Transport">

而不是

<security mode="TransportWithMessageCredential">

我收到下一个错误:

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.

按照上面的设置。
当我使用:

<security mode="Transport">

并得到错误:

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.

我做的就是接下来的改动
1) 首先在 app.config

<security mode="Transport">
  <transport clientCredentialType="Windows" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

比码处:

public static class Ssl
{
    private static readonly string[] TrustedHosts = new[] {
      "YourServiceName", 
      "YourServiceName2"
    };

    public static void EnableTrustedHosts()
    {
        ServicePointManager.ServerCertificateValidationCallback =
        (sender, certificate, chain, errors) =>
        {
            if (errors == SslPolicyErrors.None)
            {
                return true;
            }

            var request = sender as HttpWebRequest;
            if (request != null)
            {
                return TrustedHosts.Contains(request.RequestUri.Host);
            }

            return false;
        };
    }
}

并且:

YourContractInstance.ClientCredentials.Windows.ClientCredential.UserName = ***;
YourContractInstance.ClientCredentials.Windows.ClientCredential.Domain = ***;
YourContractInstance.ClientCredentials.Windows.ClientCredential.Password = ***;
YourContractInstance.ClientCredentials.Windows.AllowNtlm = true;

所有这些解决方法都是因为我在不允许访问的 SOAP 服务主机上的证书|DNS 配置有问题,所以我不得不通过 IP 添加服务引用。