イントラネットでC#WCFを使用しているASP.NET 3.5アプリケーションがあります。WCFの実行中に進行状況が更新される
サービスは、3つのコマンドをそれぞれ2-3分ずつ順番に実行します。私は、ラベルを更新するなど、実行中のコマンドでユーザーを更新したままにしておきたい。
私はこの問題について専門家ではないので、これを行うための最良の方法は何かを知りたいと思います。
ありがとう、
Ps。サービスとクライアントは、IIS 7.5を使用して同じサーバーでホストされます。
EDIT
まあ、私は過去2日間のためにこれに取り組んできました..私は専門家ではないよ:)
私は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);
}
}
}
EDIT 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!
サービスをビルドできましたが、クライアント側で関数を定義できません。私の編集をご覧ください。ありがとう。 – m0dest0
サービスの実装のための私の編集を参照してください。また、クライアント上にICallbacksを実装する必要があります – Eric
Thx Eric、私はクライアント側でコードを実装することができました(EDIT 2を参照)。最後に、なぜサービスメソッドを避けるべきかについてコメントしてくださいタイムアウトしないでください。 – m0dest0