tags:

views:

87

answers:

2

I have a WCF service, marked with the OperationContract attribute. I have a potentially long running task I want to perform when this operation is carried out, but I don't want the caller (in this case Silverlight) to have to wait for that to complete.

What is my best option for this?

I was thinking of either

  • something like the OnActionExecuted method of ActionFilterAttibute in System.Web.Mvc, but couldn't see an equivilent.
  • something listening to an event. (The process I want to call is a static, so I'm not too sure about this approach)
  • something else:

In the scenario I'm working in, I lock the app so the user cannot make any changes during the save until I get the response (a status code) back.

+3  A: 

Keep in mind, Silverlight won't actually have to 'wait' for the call to finish. When you create a service reference within Silverlight you will automatically get async calls.

Assuming you really don't need to wait for the call to finish (ie: your service method uses a 'void' return type) you can mark the service method as one-way via:

[OperationContract(IsOneWay = true)]
void MyServiceMethod(some args);
AgileJon
So what you're essentially saying have the secondary operation I want the first one to trigger as a seperate one way service?
DeletedAccount
Yes, depending on your definition of 'long running' you may want to fire off the process with one service method and then periodically ping to see if it's complete with another service method.
AgileJon
+1  A: 

In general, I suggest having another process service handle long-running actions. Create a simple Windows Service, and have it pull requests from an MSMQ queue via WCF. Have the main service post requests to the background service, then return to its caller. If anyone cares about the results, then the results may be placed in an output queue, and the Silverlight application could get them by querying the output queue.

You might also look into Windows Workflow Foundation, which is made to fit very well with WCF. In fact, you can have just this kind of service, where all the logic of the service is in the workflow. If the workflow takes too long, it can be persisted to disk until it's ready to go again.

John Saunders