【问题标题】:Error while accessing Remote Service in .net在 .net 中访问远程服务时出错
【发布时间】:2018-12-20 06:38:30
【问题描述】:

我们正在尝试通过 HTTPS 从远程系统访问 java web 服务到我们的 .net 客户端系统。我们面临一个错误:

这可能是由于在 HTTPS 情况下服务器证书未正确配置 HTTP.SYS。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的

有趣的是它在 SOAP UI 中工作,但只有 Visual Studio 的问题。为什么它在肥皂 UI 中而不是在 Visual Studio2010 中工作

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(CertificationvAlidatefunction);
            mainclass.ClientCredentials.UserName.UserName = "testuser";
            mainclass.ClientCredentials.UserName.Password = "test123";


            response = mainclass.Testmethod(request);

        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
  private bool CertificationvAlidatefunction(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
      System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors errors)
    {
        return true;

}

【问题讨论】:

  • 哪个是错误?您插入的文本是代码吗? “这可能是由于……”?
  • 是的,就是这样,但在 SOAP UI 中工作正常
  • 目前添加服务引用,报错
  • 您可以访问更新版本的 Visual Studio 吗?
  • 不,我没有。我只有 VS 2010

标签: java c# .net wcf


【解决方案1】:

dotnet 框架可能与支持的 TLS 版本有关。据我所知,。 Net4.0与tls1.2不兼容,具体可以参考以下问题。
Which versions of SSL/TLS does System.Net.WebRequest support?
使用以下代码 sn-ps 设置配置。

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
            ServiceReference2.Service1Client client = new ServiceReference2.Service1Client();
            client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication =
 new X509ServiceCertificateAuthentication()
 {
     CertificateValidationMode = X509CertificateValidationMode.None,
     RevocationMode = X509RevocationMode.NoCheck
 };

如果有什么我可以帮忙的,请随时告诉我。

【讨论】:

  • 为什么soapUI 有TLS 1.1 而OS 没有,甚至.net 没有??它会引起问题吗?
  • Tls1.1 已经支持,只要你安装了 Net4.0(vs2010 内置)。所以soapui已经设置为默认使用tls1.1。但是,此选项需要在程序中明确设置。您是否尝试在程序中设置此选项?
猜你喜欢
  • 1970-01-01
  • 2012-04-20
  • 1970-01-01
  • 1970-01-01
  • 2014-08-26
  • 1970-01-01
  • 2011-12-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多