PDA

View Full Version : Timeout error in WebAPI queries


fabrizio.dicesare
September 9th, 2015, 03:38 AM
Hi,

I'm using the web api and c#. Unfortunately, I get a timeout exception every time that I call FetchObjects() on a result set having hundreds of results.

This is a sample code I'm calling:

CommitCRM.ObjectQuery<CommitCRM.Account> accountSearch = new CommitCRM.ObjectQuery<CommitCRM.Account>();

accountSearch.AddCriteria(CommitCRM.Account.Fields .AccountNumber, CommitCRM.OperatorEnum.opEqual, number);

List<CommitCRM.Account> accounts = accountSearch.FetchObjects();



The last line of the previous code should return about 250 results, but instead it throws this timeout exception:


CommitCRM.Exception: Timeout dell'operazione.
in CommitCRM.CmtDbQryWebAPI.APICall(String sFileName, String sRequest, String& sResponse, Int32& nStatus) in d:\Progetti\CommitCRM\CommitCRM-New-API-Libs-V70-Key-dfeQ34ti8\CommitCRM-CSharp\Source\CommitLib\CommitCRM\CmtDbQryWebAPI.c s:riga 128
in CommitCRM.CmtDbQryWebAPI.CmtGetMultiRecordDataByRe cId(String xXMLRequestBuff, Int32 xXMLRequestBuffLen, StringBuilder xXMLResponseDataBuff, Int32 xXMLResponseDataBuffLen, Int32& nStatus) in d:\Progetti\CommitCRM\CommitCRM-New-API-Libs-V70-Key-dfeQ34ti8\CommitCRM-CSharp\Source\CommitLib\CommitCRM\CmtDbQryWebAPI.c s:riga 37
in CommitCRM.CmtDbQryProxy.CmtGetMultiRecordDataByRec Id(String xXMLRequestBuff, Int32 xXMLRequestBuffLen, StringBuilder xXMLResponseDataBuff, Int32 xXMLResponseDataBuffLen, Int32& nStatus) in d:\Progetti\CommitCRM\CommitCRM-New-API-Libs-V70-Key-dfeQ34ti8\CommitCRM-CSharp\Source\CommitLib\CommitCRM\CmtDbQryProxy.cs :riga 60
in CommitCRM.Object.Load(List`1 lstIDs, String fieldList) in d:\Progetti\CommitCRM\CommitCRM-New-API-Libs-V70-Key-dfeQ34ti8\CommitCRM-CSharp\Source\CommitLib\CommitCRM\Object.cs:riga 443
in CommitCRM.Object.LoadMultiple(List`1 lstRecIDs, String fieldList) in d:\Progetti\CommitCRM\CommitCRM-New-API-Libs-V70-Key-dfeQ34ti8\CommitCRM-CSharp\Source\CommitLib\CommitCRM\Object.cs:riga 522
in CommitCRM.ObjectQuery`1.FetchObjects(String fieldList) in d:\Progetti\CommitCRM\CommitCRM-New-API-Libs-V70-Key-dfeQ34ti8\CommitCRM-CSharp\Source\CommitLib\CommitCRM\QueryCommand.cs: riga 142
in CommitCRM.ObjectQuery`1.FetchObjects() in d:\Progetti\CommitCRM\CommitCRM-New-API-Libs-V70-Key-dfeQ34ti8\CommitCRM-CSharp\Source\CommitLib\CommitCRM\QueryCommand.cs: riga 126
in WebAssist.Services.AccountService.GetByNumber(Stri ng number) in d:\Progetti\WebAssist\WebAssist\Services\AccountSe rvice.cs:riga 85


The same code works without any problem if the results are about 10 or less. Also I managed to query the same data via ODBC without timeout.

Is there anything I am doing wrong with the Web API or the Web API itself has a problem in fetching hundreds of results?

Thanks in advance,

Fabrizio

Support Team
September 9th, 2015, 06:05 AM
This is not something we usually hear about but maybe the timeout happens as a result of the number of records being fetched together with the number of fields fetched for each record (when not specified it returns all fields includes from all linked tables for each record).

It may work better if you will fetch only the needed fields from Accounts instead of getting them all, for example:

lstAccounts = objQuery.FetchObjects(RangerMSP.Account.Fields.Acc ountREC_ID.Key + "," + RangerMSP.Account.Fields.FileAs.Key)

Hope this helps.

fabrizio.dicesare
September 10th, 2015, 05:25 AM
First of all, thank you for your reply.

I tried your proposed solution and it returns some results. The problem now is that the results number of your solution is 100, while the corresponding odbc query returns 264 results.

I could not find an explanation for this strange behaviour. Do you have one?

Thanks,

Fabrizio

Support Team
September 10th, 2015, 07:56 AM
Indeed by default the query object returns up to 100 records. In order to get more results you should create the object differently and add another parameter to specify the max number of records you want to fetch. Please use a reasonable number unlike a very high number:

For example, in the C# sample, we have the following:
<i>RangerMSP.ObjectQuery<RangerMSP.Account> accountSearch = new RangerMSP.ObjectQuery<RangerMSP.Account>();

The above uses the default (100). To specify a different number, you should call it like this:

RangerMSP.ObjectQuery<RangerMSP.Account> accountSearch = new RangerMSP.ObjectQuery<RangerMSP.Account>(RangerMSP.LinkEnum.linkAND, 500);

</i>

In the above line of code you will create the same AccountSearch object as in the first case, just it will ask for up to 500 rows.

Hope this helps.