I have an ASP.NET 3.5 app consuming a C# WCF in an intranet.
The service executes three commands sequentially taking 2-3 mins each. I'd like to keep the user updated with the command that is running, for example, refreshing a label.
I'm not an expert on this matter so I'd like to know what is the best way to do this.
Thanks,
Ps. The service and the client are hosted in the same server using IIS 7.5.
EDIT
Well, I've been working on this for the past two days .. I'm not an expert :)
I'm following Eric's suggestion, use of WSHttpDualBinding and a callback function.
So, I was able to build a service using duplex binding and define a callback function, however I can't define the callback function on the client side, can you please shed some light on this.
namespace WCF_DuplexContracts
{
[DataContract]
public class Command
{
[DataMember]
public int Id;
[DataMember]
public string Comments;
}
[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ICallbacks))]
public interface ICommandService
{
[OperationContract]
string ExecuteAllCommands(Command command);
}
public interface ICallbacks
{
[OperationContract(IsOneWay = true)]
void MyCallbackFunction(string callbackValue);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class CommandService : ICommandService
{
public string ExecuteAllCommands(Command command)
{
CmdOne();
//How call my callback function here to update the client??
CmdTwo();
//How call my callback function here to update the client??
CmdThree();
//How call my callback function here to update the client??
return "all commands have finished!";
}
private void CmdOne()
{
Thread.Sleep(1);
}
private void CmdTwo()
{
Thread.Sleep(2);
}
private void CmdThree()
{
Thread.Sleep(3);
}
}
}
EDIT 2
This the client implementation,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Client.DuplexServiceReference;
using System.ServiceModel;
namespace Client
{
class Program
{
public class Callback : ICommandServiceCallback
{
public void MyCallbackFunction(string callbackValue)
{
Console.WriteLine(callbackValue);
}
}
static void Main(string[] args)
{
InstanceContext ins = new InstanceContext(new Callback());
CommandServiceClient client = new CommandServiceClient(ins);
Command command = new Command();
command.Comments = "this a test";
command.Id = 5;
string Result = client.ExecuteAllCommands(command);
Console.WriteLine(Result);
}
}
}
And the result:
C:\>client
cmdOne is running
cmdTwo is running
cmdThree is running
all commands have finished!