0 Replies - 273 Views - Last Post: 06 November 2017 - 10:22 AM Rate Topic: -----

#1 sh0td0wn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 25-November 10

Occasional 500 Error when invoking EAP WCF Request in a TAP method

Posted 06 November 2017 - 10:22 AM

I have a TAP method that invokes an EAP WCF Service POST request. I'm occasionally encountering 500 errors that have this message:
An asynchronous module or handler completed while an asynchronous operation was still pending.


So I'm wondering if I'm building the TAP method correctly.
public async Task<Result> SendEmail(Email email){
        Result result = new Result();
        using(var soap = new WCFService()){
            WCFEmail wcfEmail = email;
            TaskCompletionSource<bool> tsc = new TaskCompletionSource();
            soap.SendEmailCompleted += new SendEmailCompletedEventHandler(delegate (object sender, SendEmailCompletedEventHandler e){
                if(e.Error != null)
                    tsc.TrySetException(e.Error)
                else(e.Cancelled)
                    tsc.TrySetCancelled();
                else{
                    var success = false;
                    //result logic snipped
                    tsc.TrySetResult(success);
                }
            }
            soap.SendEmailAsync(email);
            await tsc.Task;
        }
        return result;
    }


That TAP method is being invoked in an async HTTP POST Controller method in a Web API application.

public async Task<IHttpActionResult> Post([FromBody]Email email){
        var result = new Result();
        using (var svc = new EmailService()){
            result = await svc.SendEmail(email);
        }
        if(result != null){
            if(result.Success)
                return Ok("Email Sent!");
            else{
                return InternalServerError();
            }
        }
    }


Is This A Good Question/Topic? 0
  • +

Page 1 of 1