WCF:どのようにWCF PerSessionサービスへの新規接続を検出するには?

StackOverflow https://stackoverflow.com/questions/2442004

質問

私はPerSessionに設定InstanceContextModeで自己ホスト型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();
}
役に立ちましたか?

解決

あなたはサービス契約にIsInitiatingを使用することができます。

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

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

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top