The underlying connection was closed for concurrent Async request

  • Thread starter Thread starter Hirnesh Jain
  • Start date Start date
H

Hirnesh Jain

Guest
I have added web reference to my C# 4.0 project as OOPostAcknowledge and while i run code in my PC assume my table have 1000 rows so there are 1000 async request made to webservice and getting completed success response for all.

the same C# Windows application when running from windows server 2012 R2 while making 1000 async request only first approx (150 - 200) requests are posted successfully and latest getting error as

"System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive. Inner ExMessage = Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. @ : at System.Web.Services.Protocols.WebClientAsyncResult.WaitForResponse() at System.Web.Services.Protocols.WebClientProtocol.EndSend(IAsyncResult asyncResult, Object& internalAsyncState, Stream& responseStream) at System.Web.Services.Protocols.SoapHttpClientProtocol.InvokeAsyncCallback(IAsyncResult result)"



Kindly advise for the same, code below.

private void PostItemMasterAcknowledgment()
{
try
{
var ActTable = DBO.GetSqlcmdDataTable($"SELECT * FROM [dbo].[TABLE_NAME]");


var req = new OOPostAcknowledge.WebServicesProcess();
req.Timeout = 1000 * 60 * 10; // ms * sec * min -- 10 mins
req.Credentials = myCred;
bool success = false;
req.UpdateProcessedItemCompleted += Req_UpdateProcessedItemCompleted;
foreach (DataRow row in ActTable.Rows)
{
try
{
req.UpdateProcessedItemAsync(row["No"].ToString(), AckProcessed_From_API_FLAG, success, "", row["Id"].ToString());
}
catch (Exception ex)
{
Library.WriteError(ex);
}
}
}
catch (Exception ex)
{
Library.WriteError(ex);
}
finally
{
GC.Collect(); this.Cursor = Cursors.Default;
}
}


private void Req_UpdateProcessedItemCompleted(object sender, OOPostAcknowledge.UpdateProcessedItemCompletedEventArgs e)
{
try
{
if (e.Error == null && e.success && !string.IsNullOrEmpty(e.ackItemNo))
{
DBO.SqlExecuteNonQuery($"UPDATE [dbo].[TABLE_NAME] SET [STATUS] = '{AckPostStatus}', [MODIFIEDDATE] = GETDATE(), [REMARKS]= ISNULL([REMARKS],'') + ':Acknowledged {e.ackItemNo}' WHERE [No] = '{e.ackItemNo}' AND [Id] = {e.UserState.ToString()}");
}
else
{
Library.WriteError(e.Error);
}
}
catch (Exception ex)
{
Library.WriteError(ex);
}
finally
{


}
}


Hi, have tried the same code in Windows 10 PC and getting the error after 200 async requests out of 1000 request, but the same is working fine in Windows 7 and get a response for all 1000 async requests.

Is there need to do any setting need to be changed for Windows 10/Windows server 2012 to allow more async request?

or any config needs to be added in Application app.config?


Please advise.



Continue reading...
 
Back
Top