I had a problem getting a response from the API with my code, the request does not expire, and it does not give me an answer at all. I made an api endpoint in my own API to return a json string to manually publish json data with the "Firefox Poster" and this works fine. With this, I believe the problem is somewhere in my code.
I got C # WebAPI, which I am developing for use with the Angular interface (this works, this is just for the story). When calling my API, I create an "EnrollmentRequestDto" object
public class EnrollmentRequestDto {
After creating this object, I send to my class RequestHandler and the BulkEnrollRequest method, which atm is written with the HttpClient Flurl extension, which can be found here: github
public IResponse BulkEnrollRequest(EnrollmentRequestDto enrollmentRequest) { try { var result = _bulkEnrollUrl.PostJsonAsync(enrollmentRequest).ReceiveJson<SuccessResponse>(); result.Wait(); return result.Result; } catch (FlurlHttpTimeoutException) { throw new AppleTimeOutException(); } catch (FlurlHttpException ex) { return _errorHandler.DeserializeFlurlException(ex); } }
I also tried this to make sure that nothing happens in Flurl (this is just for debugging until the moment I want to get an answer):
public async Task<IResponse> BulkEnrollRequest(EnrollmentRequestDto enrollmentRequest) { var json = JsonConvert.SerializeObject(enrollmentRequest); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await httpClient.PostAsync(_bulkEnrollUrl, new StringContent(json, Encoding.UTF8, "application/json")); return new SuccessResponse(); }
And the code hangs at the waiting point, and nothing happens. I tried to set a breakpoint after BulkEnrollRequest so that it never leaves this method.
Now for the funny part: it worked when I was working on ErrorHandler, and at some point the API just stopped responding. Wireshark shows that the request is being made ... so I'm stuck.
Any help is appreciated.
EDIT
Now it works! I implemented an asynchronous path from the API controller to RequestHandler, and then expected each call. For reference:
public async Task<IResponse> BulkEnrollRequest(EnrollmentRequestDto enrollmentRequest) { try { var result = await _bulkEnrollUrl.PostJsonAsync(enrollmentRequest).ReceiveJson<SuccessResponse>(); return result; } catch (FlurlHttpTimeoutException) { throw new AppleTimeOutException(); } catch (FlurlHttpException ex) { return _errorHandler.DeserializeFlurlException(ex); } }