3

InstanceContextMode が PerSession に設定されたセルフホステッド WCF サービスがあります。
ホスト アプリケーションからサービスへの新しいクライアント接続 (セッション) を検出し、その新しいセッション コンテキストを使用して、そのイベントを通じてサービスを監視するにはどうすればよいですか?

何かのようなもの:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class MyService : IMyService {
    public event EventHandler ClientRegistered;
    public event EventHandler FileUploaded;
}

そして私のホストアプリケーションからできること:

ServiceHost svc = new ServiceHost(typeof(MyService));
svc.Open();

// something like:
svc.NewSession += new EventHandler(...)

//...

public void SessionHandler(InstanceContext SessionContext) {
    MySessionHandler NewSessionHandler = new MySessionHandler(SessionContext);

    // From MySessionHandler I handle the service's events (FileUploaded, ClientRegistered) 
    // for this session and notify the UI of any changes.
    NewSessionHandler.Handle();
}
4

1 に答える 1

3

請負契約でIsInitiatingを使用できます

[OperationContract(IsInitiating = true)]
   void FirstMethod();

次のリンクを参照してください。

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8137553a-8657-475e-b9ca-5914d9c9d57a

于 2010-03-14T11:57:24.970 に答える