イントラネットでC#WCFを使用するASP.NET3.5アプリがあります。
このサービスは、3つのコマンドを順番に実行し、それぞれ2〜3分かかります。ラベルの更新など、実行中のコマンドでユーザーを最新の状態に保ちたいです。
私はこの問題の専門家ではないので、これを行うための最良の方法を知りたいです。
ありがとう、
追伸 サービスとクライアントは、IIS7.5を使用して同じサーバーでホストされます。
編集
さて、私は過去2日間これに取り組んできました..私は専門家ではありません:)
私はEricの提案、WSHttpDualBindingの使用、およびコールバック関数に従っています。
そのため、デュプレックスバインディングを使用してサービスを構築し、コールバック関数を定義することはできましたが、クライアント側でコールバック関数を定義することはできません。これに光を当ててください。
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);
}
}
}
編集2
これはクライアントの実装です。
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);
}
}
}
そして結果:
C:\>client
cmdOne is running
cmdTwo is running
cmdThree is running
all commands have finished!