我正在使用RestClient应用程序与我的WCF服务进行通信.我收到以下异常
The underlying connection was closed: An unexpected error occurred on a receive.
Run Code Online (Sandbox Code Playgroud)
这是我使用的C#代码
string q = string.Format(@"xxxxxxxxxxxxxxxxxxxxxxxxxxx");
WebClient client = new WebClient();
string Url = string.Format("{0}/Get?queries={1}", BaseUrl,HttpUtility.UrlEncodeUnicode(q));
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
var result = client.DownloadString(Url);
Console.WriteLine("======================output================================");
Console.WriteLine(result);
Console.WriteLine("===========================================");
Run Code Online (Sandbox Code Playgroud)
这是错误消息
System.Net.WebException was caught
HResult=-2146233079
Message=The underlying connection was closed: An unexpected error occurred on a receive.
Source=System
StackTrace:
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at System.Net.WebClient.DownloadString(String address)
at RestClient.Program.GetRecordsTest() in C:\Users\Wiemon\Downloads\RestAppClient\RestAppClient\Program.cs:line 118
InnerException: System.IO.IOException
HResult=-2146232800
Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Source=System
StackTrace:
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._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
InnerException: System.Net.Sockets.SocketException
HResult=-2147467259
Message=An existing connection was forcibly closed by the remote host
Source=System
ErrorCode=10054
NativeErrorCode=10054
StackTrace:
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)
InnerException:
Run Code Online (Sandbox Code Playgroud)
这是我的约束力
<binding name="wsHttpEndpoint" >
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Certificate" />
<message clientCredentialType="Certificate" />
</security>
</binding>
Run Code Online (Sandbox Code Playgroud)
和我的端点行为,而不是我设置maxItemsInObjectGraph ="2147483647"
<behavior name="MyEndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<clientCredentials>
<clientCertificate findValue="xxxxxxxxxxxxxxxxxx" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" />
<serviceCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck" />
</serviceCertificate>
</clientCredentials>
</behavior>
Run Code Online (Sandbox Code Playgroud)
我在 WCF 中的 http 绑定深处遇到了类似的错误。
客户端 -> 底层连接已关闭:接收时发生意外错误。
客户端 -> 无法从传输连接读取数据:现有连接被远程主机强制关闭。
服务器(在“procdump”的帮助下获得此信息)-> 由于线程退出或应用程序请求,I/O 操作已中止
最终,几个小时后,我发现了 HTTP.sys 日志记录(在 C:\WINDOWS\System32\LogFiles\HTTPERR 中),并且发现 WCF 自托管服务连接由于一个模糊的配置问题而被强制删除(故意) (每秒最小发送字节数)。不幸的是,又花了几个小时来重新配置(您无法通过“netsh http add timeout”来完成此操作,因此您必须在应用程序中或非自托管时在 IIS 中执行此操作)。
| 归档时间: |
|
| 查看次数: |
21752 次 |
| 最近记录: |