views:

35

answers:

3

Hi all,

I have a web service that executes a task that may take hours to finish (asynchronously)

I would like to share the status of that task by all the clients that connects to the server (I'm using a web application for this)

For example, the first client that calls the page http://localhost/process.aspx will instantiate the web service and it will call a method to start executing the task. A percentage number will be displayed showing the status of completion. I can do this by polling the web service using AJAX.

If there is another client that tries to opens that page, it should get the same percentage information so no new instances of the web service are created.

How is the best way of doing this? I thought about different solutions but sooner or later I find new problems. These are some of the possible alternatives:

  • Create an static object of the Web service.
  • Create the object in the global.asax file.

Do you guys have any other ideas? I'm not too familiar designing web sites and this is driving me crazy. I would appreciate if you guys could provide some code snippets.

Thanks

A: 

The issue is ensuring that the information pertaining to the single instance of a process is stored in exactly one place.

Your initial thinking can be applied, for instance, by using the Application object, but that will break down in a clustered IIS scenario.

I am not posative that a database is the absolute best solution, but I believe it would give you what you want.

If 100 clients try to start the process at the same time, only one can succeed, right? The databases locking facility will help you make that happen.

Gabriel
A: 

There's a method (I'm assuming WCF for the web service) that allows you to have exactly one instance of the service run... link

I think this is what you are trying to accomplish.

Richard B
Thanks for this. Yes, it looks basically what i need. The problem is if I call MyContractProxy proxy1 = new MyContractProxy(); several times, still creates several objects and the same instance is not shared.
A: 

Assuming I have understood your requirements correctly. Your webservice should not be creating the instance of the “worker” object.

Your webservice request should log to either a database (as the other poster noted) or a messagequeue of somesort. At this point your “worker” processer (probably some type of service) should take over the job as it requires.

Basically you want to break up your application into something like this

| Webservice | ---------- | Datastore |-----------| Worker |

Any further requests regarding the batch should be managed by the webservice querying the datastore.

Remember webservices are NOT DESIGNED TO DO WORK.

Maxim Gershkovich