Since converting from SOAP, I’ve run into C# issues related specifically to the Sales Price (AR202000) page. For instance, when using a PUT method to create a brand new Sales Price row, I need to use a CancellationToken to timeout after 5 seconds. Otherwise, I need to wait 5+ minutes to get a response back (InnerException: Error while copying content to a stream). This is very strange since there is no wait time at all using Postman. This isn’t my biggest concern since I’ve worked around it with the timeout/cancellation.
My biggest problem occurs when using a PUT method just to retrieve a Sales Price row (using InventoryID/PriceType/PriceCode). This can take anywhere between 1 second to 5 minutes just to retrieve a response. I need to do this to retrieve the RecordID, which is a new REST requirement for deleting specific SalePrice rows. I don’t receive any response errors like I do trying to create the Sales Price row. This is drastically increasing the processing time compared to my SOAP implementation. These particular REST issues aren’t happening with other Acumatica page as I haven’t run into these kind of issues before using HttpClient.
Did anyone else run into these issues or found a way around the huge extended wait time?
Here my code (the sharedClient is of type HttpClient/RESTmethod is the URL):
var json = JsonSerializer.Serialize(body);
var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
sharedClient.DefaultRequestHeaders.Accept.Clear();
sharedClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string result = string.Empty;
using (CancellationTokenSource cancelAfterDelay = new CancellationTokenSource(TimeSpan.FromSeconds(seconds)))
{
var response = new HttpResponseMessage();
if (post)
response = sharedClient.PostAsync(RESTmethod, httpContent, cancelAfterDelay.Token).Result;
else
response = sharedClient.PutAsync(RESTmethod, httpContent, cancelAfterDelay.Token).Result;
var respBody = response.Content.ReadAsStringAsync();
result = respBody.Result;
}