我有一个简单的web服务调用,由。net (c#) 2.0 Windows应用程序生成,通过Visual Studio生成的web服务代理,用于同样用c#(2.0)编写的web服务。这种方法已经有效了好几年,并且在十几个正在运行的地方继续有效。

在新地点的新安装遇到了问题。当试图调用web服务时,它失败了,消息说:

无法为SSL/TLS安全建立信任关系 通道

web服务的URL使用SSL (https://)——但这已经在许多其他位置工作了很长时间(并继续这样做)。

我该往哪里看?这可能是Windows和。net之间的安全问题,是此安装独有的吗?如果是,我在哪里建立信任关系?我迷路了!


当前回答

我刚刚遇到了这个问题。我的解决方案是通过手动同步时间服务器来更新系统时间。要做到这一点,你可以:

右键单击任务栏中的时钟 选择“调整日期/时间” 选择“Internet Time”选项卡 单击“更改设置” 选择立即更新

在我的情况下,这是不正确的同步,所以我必须点击它几次才能正确更新。如果它继续不正确地更新,您甚至可以尝试从服务器下拉菜单中使用不同的时间服务器。

其他回答

想法(基于过去的痛苦):

do you have DNS and line-of-sight to the server? are you using the correct name from the certificate? is the certificate still valid? is a badly configured load balancer messing things up? does the new server machine have the clock set correctly (i.e. so that the UTC time is correct [ignore local time, it is largely irrelevent]) - this certainly matters for WCF, so may impact regular SOAP? is there a certificate trust chain issue? if you browse from the server to the soap service, can you get SSL? related to the above - has the certificate been installed to the correct location? (you may need a copy in Trusted Root Certification Authorities) is the server's machine-level proxy set correctly? (which different to the user's proxy); see proxycfg for XP / 2003 (not sure about Vista etc)

如果没有工作坏证书,当ServerCertificateValidationCallback返回true; 我的ServerCertificateValidationCallback代码:

ServicePointManager.ServerCertificateValidationCallback += delegate
{
    LogWriter.LogInfo("Проверка сертификата отключена, на уровне ServerCertificateValidationCallback");
    return true;
};

我的代码被阻止执行ServerCertificateValidationCallback:

     if (!(ServicePointManager.CertificatePolicy is CertificateValidation))
    {
        CertificateValidation certValidate = new CertificateValidation();
        certValidate.ValidatingError += new CertificateValidation.ValidateCertificateEventHandler(this.OnValidateCertificateError);
        ServicePointManager.CertificatePolicy = certValidate;
    }

OnValidateCertificateError功能:

private void OnValidateCertificateError(object sender, CertificateValidationEventArgs e)
{
    string msg = string.Format(Strings.OnValidateCertificateError, e.Request.RequestUri, e.Certificate.GetName(), e.Problem, new Win32Exception(e.Problem).Message);
    LogWriter.LogError(msg);
    //Message.ShowError(msg);
}

我禁用了CertificateValidation代码和ServerCertificateValidationCallback运行得很好

微软的SSL诊断工具可能能够帮助识别问题。

更新链接已经修复。

我刚刚遇到了这个问题。我的解决方案是通过手动同步时间服务器来更新系统时间。要做到这一点,你可以:

右键单击任务栏中的时钟 选择“调整日期/时间” 选择“Internet Time”选项卡 单击“更改设置” 选择立即更新

在我的情况下,这是不正确的同步,所以我必须点击它几次才能正确更新。如果它继续不正确地更新,您甚至可以尝试从服务器下拉菜单中使用不同的时间服务器。

如果你使用的是Windows 2003,你可以这样做:

Open Microsoft Management Console (Start --> Run --> mmc.exe); Choose File --> Add/Remove Snap-in; In the Standalone tab, choose Add; Choose the Certificates snap-in, and click Add; In the wizard, choose the Computer Account, and then choose Local Computer. Press Finish to end the wizard; Close the Add/Remove Snap-in dialog; Navigate to Certificates (Local Computer) and choose a store to import: If you have the Root CA certificate for the company that issued the certificate, choose Trusted Root Certification Authorities; If you have the certificate for the server itself, choose Other People Right-click the store and choose All Tasks --> Import Follow the wizard and provide the certificate file you have; After that, simply restart IIS and try calling the web service again.

参考:http://www.outsystems.com/NetworkForums/ViewTopic.aspx?Topic=Web-Services: -Could-not-establish-trust-relationship-for-the-SSL / TLS -…