【问题标题】:Configuring winform app to call SOAP https with windows autentication配置 winforms 应用程序以使用 Windows 身份验证调用 SOAP https
【发布时间】:2017-02-14 05:24:38
【问题描述】:

我有一个我正在尝试使用的 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'...

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

提前致谢。
最大

附注:
如果我这样做了

<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'.

【问题讨论】:

    标签: c# winforms web-services soap service-reference


    【解决方案1】:

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

    <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 添加服务引用。

    【讨论】:

      猜你喜欢
      • 2013-04-09
      • 1970-01-01
      • 2014-08-03
      • 2011-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      相关资源
      最近更新 更多