none
The underlying connection was closed for concurrent Async request RRS feed

  • Question

  • 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.


    Tuesday, July 9, 2019 12:26 PM

All replies

  • This looks overall to be a poor design where thousands of calls must be made to a Web service to post data to a backend database?

    Why can't the Web service accept a collection of data objects (DTO(s)) or a single table of data in a single post of data from the client to the service, instead of this 1,000 or more async calls to the service that's choking it?

    What lead you in trying to implement async in the solution that's not working out?


    • Edited by DA924x Tuesday, July 9, 2019 1:12 PM
    Tuesday, July 9, 2019 1:11 PM
  • Hi Hirnesh Jain, 

    Thank you for posting here.

    I try to do the sample based on your code, but I need more information to do the test.

    Please provide some code about ’ DBO’, ‘OOPostAcknowledge’ and ‘AckPostStatus’, it will help us to analyze your problem.

    Besides, what's the type of your project? ASP.NET?

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 10, 2019 6:34 AM
  • Hi Xingyu,

    The DBO is just a static helper class for all SQL Db operation here is the code for DBO.SqlExecuteNonQuery

    public static int SqlExecuteNonQuery(string cmdText)
            {
                var conn = GetSqlConnection();
                try
                {
                    using (SqlCommand cmd = new SqlCommand(cmdText, conn) { CommandTimeout = 0 })
                    {
                        return cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    Library.WriteError(ex);
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }

    And the OOPostAcknowledge is the webreference name given for the URL iam trying to post the data (http://185.64.26.76:7047/DynamicsNAV100/WS/Enhance/Codeunit/WebServicesProcess).

    And AckPostStatus is string variable with value 'A' (Acknowledged).

    This is a C# code written in dotnet 4.0 framework in a windows form application.

    I believe this should help to analyse the issue i am facing.

    Regards,

    Hirnesh Jain


    Sunday, July 28, 2019 10:02 AM
  • Dear,

    As part of our integration program we are trying to pull data form Microsoft NAV Dynamic ERP where we are shared the JSON API to consume the data for different transactions like Itemmaster, sales,purchase, etc..

    As the data load shall not be high we agreed to acknowledge the data once received by unique field in each table.. and data once acknowledged by receiver (me) shall not be send again by the sender (NAV ERP)

    Example (Itemcode in Itemmaster, Receiptno on in sales, etc..).

    Since the data volume is high considering different tables and we decided to use async to make the process faster .

    and since then we are facing the problem mentioned above.

    I have discussed with the technical team of Microsoft NAV Dynamics of about this error and they are also unsure of the root cause.

    Please help to identify the root cause and where the appropriate solution need to be done.

    1. Is there any configuration need to be done at NAV dynamics server to accept the load ?

    2. Or do we need to modify the C# code (shown above) to better process to posting ? (There are about 27 JSON API we need to consume on daily basis with over 50K records, the synchronous process is slow and takes hours for posting the 50K+ lines ) hence need a adequate solution.

    Kindly assist.

    Regards,

    Hirnesh Jain

    Sunday, July 28, 2019 10:21 AM
  • Hi Hirnesh Jain,

    Thanks for your feedback.

    I hope the following reference can help you.

    The underlying connection was closed: An unexpected error occurred on a receive

    Besides, Considering the code you provided have no obvious problems, I suggest you ask the person who answered the question in Microsoft Dynamics NAV Forum for more help.Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, July 30, 2019 10:04 AM
  • Hi Xingyu,

    The person for Microsoft Dynamics NAV is not Microsoft hes just a developer skill in NAV ERP working for private company with whom we are doing the integration. 

    would request your help you can help with anything with the code block in C# i shared to resolve the issue.

    Regards,
    Hirnesh 
    Tuesday, July 30, 2019 10:51 AM
  • Hi Hirnesh Jain, 

    Thanks for your feedback.

    Considering your code works fine in Windows 7 and gets exceptions in Windows 10/Windows Server 2012, C# forum may be not a good choice.

    Therefore, I will move it to Where is the Forum For…? forum to redirect it to the correct forum.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 31, 2019 8:39 AM