Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I've written a web service under Visual Studio in C# that has some service methods.
All works quick and fine in the client APP under Windows.
But if i use one method named "GetCertInfos" in a loop the loop gets
after a random amount of "GetCertInfos" calls into a timeout Exception.

The web method :

C#
[WebMethod]
public string[] GetCertInfos(long certID)
{
            string[] result = { };

            DataRow[] rowsFound = dataManager.MainDataSet.tbl_Certificates.Select(String.Format("CertID = {0}", certID));

            if (rowsFound.Length > 0)
            {
                DataRow rw = (DataRow)rowsFound[0];
                result = new string[]{ rw["CertID"].ToString(),
                                       rw["CertNumber"].ToString(),
                                       rw["Description"].ToString(),
                                       rw["QuestionsCount"].ToString(),
                                       rw["SingleChoiceAnswers"].ToString(),
                                       rw["TimeIndex_Min"].ToString(),
                                       rw["TestPassPercentage"].ToString() };
            }

            return result;
}


the client loop code :

C#
foreach (long certID in certIDs)
            { 
                UserCertInfo certInfoTest = new UserCertInfo();
                certInfoTest.CertID = certID;
                certInfoTest.CertInfos = serviceManagerClient.GetCertInfos(certID);
                certInfoTest.UserOwned = ownedCerts.Contains(certID);
                int index = ownedCerts.LastIndexOf(certID);
                certInfoTest.PayedTests = 0;
                if (index >= 0)
                    certInfoTest.PayedTests = payedTests[index];

                result.Add(certInfoTest); 
}


What I have tried:

Increasing operationtimeout in service inner channel,
Setting Execution timeout in App.config

<system.web>
        <httpruntime executiontimeout="180">
Posted
Updated 6-Apr-23 10:34am
v2
Comments
[no name] 6-Apr-23 11:51am    
Probably flooding the server with trivial requests instead of formulating and handling a proper query.
Member 1823449 6-Apr-23 16:35pm    
With this hint i found a solution. Thank you very much Gerry

1 solution

I wrote a new Method which needs only one service call for multi certIDs :

[WebMethod]
public string[] GetMultiCertsInfos(long[] certIDs)
{
List<string> result = new List<string>();

try
{
foreach (long certID in certIDs)
{
DataRow[] rowsFound = dataManager.MainDataSet.tbl_Certificates.Select(String.Format("CertID = {0}", certID));

if (rowsFound.Length > 0)
{
DataRow rw = (DataRow)rowsFound[0];
string resultPart = String.Join("|", new string[]{ rw["CertID"].ToString(),
rw["CertNumber"].ToString(),
rw["Description"].ToString(),
rw["QuestionsCount"].ToString(),
rw["SingleChoiceAnswers"].ToString(),
rw["TimeIndex_Min"].ToString(),
rw["TestPassPercentage"].ToString() });
result.Add(resultPart);

logMessage(String.Format("Info für Zertifikat mit ID = {0} : {1}", certID, resultPart));
}
}
}
catch (Exception ex)
{
logMessage(ex.ToString());
}

return result.ToArray();
}
 
Share this answer
 
Comments
[no name] 6-Apr-23 17:17pm    
Thanks for sharing that solution, looks good

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900