PRB: "System.Net.WebException. The Underlying Connection Was Closed. Could Not Establish Trust Relationship with Remote Server." Error Message When You Upgrade the .NET Framework (823177)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework) 1.0
- Microsoft Common Language Runtime (included with the .NET Framework 1.1)
- Microsoft Common Language Runtime (included with the .NET Framework) 1.0
- Microsoft ASP.NET (included with the .NET Framework 1.1)
- Microsoft Web Services (included with the .NET Framework) 1.0
SYMPTOMSWhen you install the Microsoft .NET Framework version 1.0 Service Pack 2 or you upgrade
to the .NET Framework version 1.1 from the .NET Framework version 1.0, your Web service clients may receive
the following error message on a call to a Web service. This error message occurs when you use Secure
Socket Layer (SSL). System.Net.WebException. The
underlying connection was closed. Could not establish trust relationship with
remote server. The error message may appear after you install or after you upgrade even though
the code works as you expect. CAUSE
Beginning with the .NET
Framework version 1.0 Service Pack 2 and with the .NET
Framework version 1.1 and later, the name that is used on the HTTP request must match
the name of the server that is issued with the SSL certificate. Earlier
SSL certificates may no longer be accepted under certain circumstances. Also, the
Certificate Revocation List (CRL) is now examined to make sure that the
certificate has not been revoked.
Other scenarios exist also. For example,
some networks use a different name-resolution scheme for internal versus
external clients. In cases where the certificate is issued to a server
with a public URL (such as www.adatum.com) and with intranet applications,
the internal Domain Name System (DNS) Server provides a different name for the same server (such as
www.internal.corporate.adatum.com). Requests for this Web service over SSL
may fail. This change is made to enhance the security of Web services that use
SSL.
Note The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, places, or events is intended or must be inferred.RESOLUTIONYou can resolve this problem by using either of the following methods: - You can change the name-resolution scheme so that DNS
provides the same name for a server. The same name for the server must be used whether the server is referred to from in the company
or from outside the company.
For example, assume that a
certificate has been issued to the URL www.adatum.com. Any Web service
application that is referred from outside the organization is called by using the
external DNS resolution schema (www.adatum.com). When an intranet Web
service application is called, the internal DNS translates the name of the
site as www.internal.corporate.adatum.com. Therefore, any request for the Web
Service over SSL may fail unless you change the name-resolution scheme. - The host name that is used when you add a Web reference to a Web
service in the Web service client must be the same name as the name that the
certificate is issued to.
WORKAROUNDTo work around this problem, you can implement
ICertificatePolicy. Then you must pass ICertificatePolicy to ServicePointManager.CertificatePolicy
before the Web Service method call is made. The following sample code implements
ICertificatePolicy and then accepts every request under SSL: Microsoft Visual Basic .NETImport the following two namespaces, and then implement the class: Imports System.Net
Imports System.Security.Cryptography.X509Certificates
Public Class MyPolicy
Implements ICertificatePolicy
Public Function CheckValidationResult(ByVal srvPoint As ServicePoint, _
ByVal cert As X509Certificate, ByVal request As WebRequest, _
ByVal certificateProblem As Integer) _
As Boolean Implements ICertificatePolicy.CheckValidationResult
'Return True to force the certificate to be accepted.
Return True
End Function
End Class Microsoft Visual C# .NETImport the following two namespaces, and then implement the class: using System.Net;
using System.Security.Cryptography.X509Certificates;
public class MyPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint
, X509Certificate certificate
, WebRequest request
, int certificateProblem) {
//Return True to force the certificate to be accepted.
return true;
} // end CheckValidationResult
} // class MyPolicy
Include the following code in the client code. Before you make the Web Service method call from the client code, the following statement (in either Visual Basic .NET or Visual C# .NET, as appropriate) must be executed: Visual Basic .NETSystem.Net.ServicePointManager.CertificatePolicy = New MyPolicy() Visual C# .NETSystem.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
STATUS
This behavior is by design.REFERENCESFor additional information about ASP.NET security enhancements and SSL, visit the following Microsoft Developer Network (MSDN) Web site: For
additional information about configuring ASP.NET and IIS to use SSL, visit the following Microsoft Developer Network (MSDN) Web site: For
additional information about how to add and how to remove Web references, visit the following Microsoft Developer Network (MSDN) Web site:
Modification Type: | Minor | Last Reviewed: | 7/8/2005 |
---|
Keywords: | kbprb kberrmsg kbWebServices kbDev kbCertServices kbSecurity KB823177 kbAudDeveloper kbAudITPRO |
---|
|