通过使用浏览器或HttpWebRequest,我对该IP使用HTTPS没有问题。
我已经创建了一个测试程序来将我的问题缩小到它的基本本质,您可以在这里查看它,如果您想:
TestViaTcp
{"Authentication failed because the remote party has closed the transport stream."}
[System.IO.IOException]: {"Authentication failed because the remote party has closed the transport stream."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Authentication failed because the remote party has closed the transport stream."
Source: "System"
TargetSite: {Void StartReadFrame(Byte[], Int32, System.Net.AsyncProtocolRequest)}
下面是附加的堆栈跟踪:
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.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at DeriveClassNameSpace.Services.Web.TcpMessaging.TestViaTcp(IPEndPoint endpoint, String auth, Boolean useSSL)
关于问题所在的最大暗示可能是“起作用,不起作用,起作用,不起作用”的模式,是什么导致了这种情况?我能做些什么来避免我遇到的IOException?当我使用HttpWebRequest处理HTTPS时,有没有什么方法可以让我看到“总是工作”的行为?
注意:我正在与之通信的服务器可以配置它监听的端口和它期望的协议,但在其他方面是完全不可修改的。
另请注意:我已经读到.NET3.5在SP1之前的SslStream有这个特殊的问题,但是我有SP1并且我的程序是针对3.5构建的,所以我假设这不是我在这里遇到的“已知错误”。