When I try to call WCF Service asynchronously from my web application after button click, I get this error:
[InvalidOperationException: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>.]
Code
protected async void btnStartPrintJob_Click(object sender, EventArgs e) { await RunPrintJOB(); } private async Task<int> RunPrintJOB() { PdfService.ServiceClient client = null; int value = 0; try { client = new PdfService.ServiceClient(); string destination = Setting.Temp + Guid.NewGuid() + ".pdf"; if (jobFileUpload.HasFile) { value = await client.RunPrintJobAsync(new MemoryStream(jobFileUpload.FileBytes), destination); } } catch (Exception ex) { } finally { client.Close(); } return value; }
Please can someone help me fix this.
Thanks