Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Windows event viewer logging the API error

Hi Experts,

When the following function runs, the windows event viewer is logging the attached error.  Any help is greatly appriciated!  

public void EndCheckForEisEmails(IAsyncResult result) {
                  var response = ((ServiceResponsePaged<EisEmail>)(((ChannelInvokeAsyncResult)result).Result));
                  if (response.Status == ResponseStatus.Success) {
                        var baseUrl = (string) result.AsyncState;
                        //We have to hit our own api to get a valid request context so that we can trigger the rule. Currently we have no request context
                var apiUrl = string.Format("{0}/api/siteevent/SendEisEmails", baseUrl);

Thanks in advance.
                        var emails = response.PagedData;
                        var jsonFormatter = new JsonMediaTypeFormatter();
                        var client = new HttpClient();
                        //var responseMessage = client.GetAsync("RecyclingClaimsProcessed");
                        const int numberOfItemsToprocess = 20;
                int pages = (emails.Count() / numberOfItemsToprocess) + 1;
                for (var i = 0; i < pages; i++) {
                    var responseMessage =
                        client.PostAsync(apiUrl, emails.Skip(i*numberOfItemsToprocess).Take(numberOfItemsToprocess).ToArray(),
                            jsonFormatter).Result;
                              
                    //This forces a pause, this is by design, we don't want to create too many requests.
                    if (!responseMessage.IsSuccessStatusCode) {
                        Logger.Error("Error while trying to post to SendEisEmails " + responseMessage.RequestMessage);
                    }
                }
                  }
EISError.txt
Avatar of ste5an
ste5an
Flag of Germany image

First of all: Please use the CODE button to embed code into your posts. This increases the readability of your posts.

Then: the log clearly states it..
An unhandled exception occurred and the process was terminated.

You're method itself has no error handling, although it is using external, not reliable resources (HttpClient and call to the net).

The further obvious things are:
The underlying connection was closed: An unexpected error occurred on a send.
An existing connection was forcibly closed by the remote host

Thus the server you've called, has terminated the connection. Cause?? Maybe a malformed request, maybe you've already exceeded your quotas or even a real network issue.
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Thanks for your suggestion. I would definitely use the code button next time. I didn't know it was there.  
Regarding the problem, it is a production error.I have not written this code. I do not have lots of flexibility to change any code.  The problem is, one email is not going through when it is called using  "client.PostAsync" and throwing that exception.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your suggestion!!