访问https服务器上托管的Webservice

我正在访问一个在SSL认证的网络服务器中托管的webserivce https://www.example.net/somewebservice/somemethod.asmx

但是当我创建一个代理类并使用C#消费它时:我收到了这个错误

事件类型:错误事件源:XXXX事件类别:无事件ID:0日期:22/08/2011时间:14:15:53用户:N / A计算机:XXXX描述:System.Net.WebException:底层连接是已关闭:无法为SSL / TLS安全通道建立信任关系。 —> System.Security.Authentication.AuthenticationException:根据validation程序,远程证书无效。 System.Net.Security.SslState.StartSendSlogb上的System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken消息,AsyncProtocolRequest asyncRequest,exceptionexception)处于System.Net.Security.SslState.StartSendBlob(Byte [SystemToken消息,AsyncProtocolRequest asyncRequest) System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,System.Net.Security.SslState.ProcessReceivedBlob(Byte []缓冲区,Int32计数,AsyncProtocolRequest asyncRequest)中的传入,Int32计数,AsyncProtocolRequest asyncRequest), System.Net.Security.SslState.StartSendBlob上的System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken消息,AsyncProtocolRequest asyncRequest)处的System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest)上的AsyncProtocolRequest asyncRequest)( System.Net.Security.SslState.ProcessReceivedBlob(Byte []缓冲区中的字节[]传入,Int32计数,AsyncProtocolRequest asyncRequest),I 系统上System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest)的System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)中的nt32计数,AsyncProtocolRequest asyncRequest)。 System.Net.Security.SslState.ProcessReceivedBlob(Byte [])的System.Net.Security.SslState.StartSendBlob(Byte []传入,Int32计数,AsyncProtocolRequest asyncRequest)中的Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message,AsyncProtocolRequest asyncRequest)在System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest)的System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)处的缓冲区,Int32计数,AsyncProtocolRequest asyncRequest)在System.Net.Security.SslState.StartSendBlob(Byte []中的System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message,AsyncProtocolRequest asyncRequest) System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest)上的System.Net.Security.SslState.ProcessReceivedBlob(Byte []缓冲区,Int32计数,AsyncProtocolRequest asyncRequest)中的,即Int32计数,AsyncProtocolRequest asyncRequest) System.Net.Security.SslState.StartSendBlob(字节)处的System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken消息,AsyncProtocolRequest asyncRequest)处的System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest)处的asyncRequest) System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes中的System.Net.Security.SslState.ProcessReceivedBlob(Byte []缓冲区,Int32计数,AsyncProtocolRequest asyncRequest)的[]传入,Int32计数,AsyncProtocolRequest asyncRequest) System.Net.Security.SslState.CheckCompletionBeforeN上的System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest)中的AsyncProtocolRequest asyncRequest) System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,Byte [] buffer,AsyncProtocolRequest)上的System.Net.Security.SslState.StartSendBlob(Byte [] incoming,Int32 count,AsyncProtocolRequest asyncRequest)中的extReceive(ProtocolToken消息,AsyncProtocolRequest asyncRequest) asyncRequest)System.Net上的System.Net.Se.SlsStream.CallProcessAuthentication(对象状态)中的System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)处于System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup的System.Threading.ExecutionContext.runTryCode(Object userData) System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态)在System.Net上的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)中的(TryCode代码,CleanupCode,backoutCode,Object userData) System.Net.TlsStream.Write上的.TlsStream.ProcessAuthentication(LazyAsyncResult结果)(Byte [] 在System.Net.ConnectStream.WriteHeaders(布尔异步)处的System.Net.PooledStream.Write(Byte []缓冲区,Int32偏移量,Int32大小)处的缓冲区,Int32偏移量,Int32大小)—内部exception堆栈跟踪的结束 – – 位于System.Web.Services.Protocols.Protocols.SrotapHttpClientProtocol.Invoke的System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest请求)中的System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest请求)(String methodName,对象[]参数)在

您的SSL证书似乎是自签名的,或者不是来自受信任的CA的自签名

System.Net.WebException:基础连接已关闭:无法为SSL / TLS安全通道建立信任关系。

让我相信……最简单的解决方案: 安装一个值得信赖的证书 ……

绝对不适合生产
其他解决方案是修改客户端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(); 

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

看起来你的服务器提供了无效的SSL证书… 结账这篇文章应该有助于避免这个问题。

你也可以尝试这个链接