0

我们正在开发一个与soap web 服务通信的.Net 应用程序(为.net 4.0 编译)。

检索 http Web 响应内容时,该应用程序在多台机器上运行良好。但是,在其中一台机器(Windows Server 2008 R2)上,应用程序无法检索响应。这是一个代码示例:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://200.57.3.82:3443/AdministradorQr/WebServiceDodaPort?wsdl");
request.Method = "GET";
WebResponse response;
Stream responseStream = response.GetResponseStream();
string result = string.Empty;
using (StreamReader streamReader = new StreamReader(responseStream))
{
   result = streamReader.ReadToEnd();
}

我们得到的例外是:

The underlying connection was closed: An unexpected error occurred on a send. System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
   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.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   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.Net.HttpWebRequest.GetResponse()

问题是,使用具有不同 URL 的相同代码,我们会得到一个成功的响应,并且问题只发生在一台机器上,即使还有另一台机器也使用 Windows 2008 工作得很好。

目前,我们无法升级 .net 框架以尝试使用在某些地方发现的 TLS 1.2 等解决方案:“底层连接已关闭:发送时发生意外错误。” 使用 SSL 证书

正如我所提到的,同样的代码在使用相同 Windows/.net 版本的其他机器上运行良好,这很奇怪,对于http://www.yahoo.com等其他 URL运行良好也很奇怪

4

1 回答 1

0

不确定它是否可以帮助您,但您可以尝试在“Global.asax -> Application_Start”函数中添加以下行。看看它的工作原理。基本上,此代码将强制您的应用程序仅使用 TLS1.2,您无需升级框架。

“System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;”

于 2019-12-19T13:34:23.897 回答