WCF:如何检测 WCF PerSession 服务的新连接?
我有一个自托管 WCF 服务,其 InstanceContextMode 设置为 PerSession。
如何从主机应用程序检测到我的服务的新客户端连接(会话),并使用新的会话上下文通过其事件观察我的服务?
类似:
[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();
}
I have a self-hosted WCF service with the InstanceContextMode set to PerSession.
How can I detect new client connections (sessions) to my service from the host application and use that new session context to observe my service through its events?
Something like:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class MyService : IMyService {
public event EventHandler ClientRegistered;
public event EventHandler FileUploaded;
}
and from my host application to be able to do:
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在服务合同中使用 IsInitiating
请参阅以下链接:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8137553a-8657-475e-b9ca-5914d9c9d57a
You can use IsInitiating in the service contract
See the following link:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8137553a-8657-475e-b9ca-5914d9c9d57a