By Sathish


2011-08-22 13:43:52 8 Comments

I am accessing a webserivce which hosted in a SSL certified webserver https://www.example.net/somewebservice/somemethod.asmx

But when I create a proxy class and consume it using C#: I am getting this error

Event Type: Error Event Source: XXXX Event Category: None Event ID: 0 Date: 22/08/2011 Time: 14:15:53 User: N/A Computer: XXXX Description: System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure. at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.TlsStream.CallProcessAuthentication(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.ConnectStream.WriteHeaders(Boolean async) --- End of inner exception stack trace --- at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at

2 comments

@Yahia 2011-08-22 13:52:12

It seems that your SSL certificate is self-signed or not from a CA which is trusted as this

System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

leads me to believe... easiest solution: install a trusted certificate...

ABSOLUTELY NOT FOR PRODUCTION
other solution would be to modify the clientside Validation

public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
 public TrustAllCertificatePolicy()
 {}

 public bool CheckValidationResult(ServicePoint sp,
  X509Certificate cert,WebRequest req, int problem)
 {
  return true;
 }
}

// this needs to be done once before the first webservice call
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

see http://weblogs.asp.net/jan/archive/2003/12/04/41154.aspx

@Sathish 2011-08-22 14:18:00

Thanks Yahia. I will install the certificate and test

@Jaans 2013-10-16 12:04:35

CertificatePolicy is now obsolete. Use ServerCertificateValidationCallback instead. And no, still not for production :-) msdn.microsoft.com/en-us/library/vstudio/…

@Anantha Sharma 2011-08-22 13:51:42

looks like your server is providing an invalid SSL certificate... checkout this article it should help in avoiding this problem.

also you can try this link

@Sathish 2011-08-22 14:17:28

Thanks Anantha. I will try

Related Questions

Sponsored Content

3 Answered Questions

[SOLVED] System.IO.IOException: The handshake failed due to an unexpected > packet format?

  • 2011-03-03 09:21:56
  • TheLearner
  • 33399 View
  • 18 Score
  • 3 Answer
  • Tags:   c# wcf

2 Answered Questions

1 Answered Questions

https using manual ssl cert with kestrel useHttps

0 Answered Questions

Error on production server

5 Answered Questions

[SOLVED] Getting EOF exception over https call

  • 2011-03-21 19:26:15
  • Amzath
  • 23417 View
  • 11 Score
  • 5 Answer
  • Tags:   .net http

0 Answered Questions

PowerShell + HttpWebRequest throws exception

1 Answered Questions

How do access a secure website within a sharepoint webpart?

Sponsored Content