Link to home
Create AccountLog in
Avatar of RTSol
RTSol

asked on

Call web service Asynchronously

Hi,

I have a web page in which there is a User Control. In this there is a call to a web service that will start a work that can last up to 5 minutes. Now, the web service returns nothing and takes no parameters. It works against the database and creates a number of PDF documents and stores them in the database. My call to the web service looks like this:

            Service1Client client = new Service1Client();
            client.makeInvoices();
            client.Close();

My problem, as you can understand, is that my web page is waiting for a result from the web service and thus freezes and eventually crashes from the timeout. All I want to do is to start the web service and then forget about it and serve the page to the client. It works as expected in that the web service finishes its job even if the page crashes. My web service (WCF) looks like this:

Service1.svc:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using Aspose.Words;

namespace invoiceService
{
    public class Service1 : IService1
    {

        public void makeInvoices()
        {
            // very time consuming job
        }

    }

}

IService1.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace invoiceService
{
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        void makeInvoices();

    }
}

How can I get the desired functionality?

Best regards
RTSol
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of RTSol
RTSol

ASKER

Thanks guys,

Have it working now.

Best regards
RTSol