[英]Force a client to call a method on the service?
I'm wondering if there's any way to force a client to call a specific method on a duplex WCF service. 我想知道是否有任何方法可以强制客户端在双工WCF服务上调用特定方法。 My situation is this, my service implementation is going to keep a collection of subscribers.
我的情况是这样,我的服务实现将保留一组订户。 The problem with this approach is, what if the client doesn't call Subscribe()?
这种方法的问题是,如果客户端不调用Subscribe()怎么办? I was thinking that in my client interface, I'd have a method called Subscribe, but that doesn't get me anywhere since the code to actually call the service can still be left out of the implementation.
我当时在想,在我的客户端界面中,会有一个名为“订阅”的方法,但这并没有帮助我,因为实际调用该服务的代码仍然可以忽略在实现中。 Is this possible?
这可能吗?
Thanks! 谢谢!
Duplex WCF service uses WCF session so you can mark your Subscribe method with: 双工WCF服务使用WCF会话,因此您可以使用以下方式标记您的Subscribe方法:
[OperationContract(IsInitiating=true)]
void Subscribe();
All other methods will have IsInitiating=false
and because of that Subscribe
method will have to be the first method called to start a new session. 所有其他方法将具有
IsInitiating=false
,因此,必须将Subscribe
方法作为开始新会话的第一个方法。 You can also have special method with IsTerminating=true
to close the session. 您还可以使用带有
IsTerminating=true
特殊方法来关闭会话。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.