在 RESTful 服务内使用 WCF Duplex 服务
假设我想创建一个 WCF WebHTTP 服务(“ServiceREST”),该服务引用了双工服务(“ServiceDuplex”)。 ServiceDuplex 需要实现某些回调成员来传递所请求的数据。例如,对 ServiceDuplex 上的 GetCustomers 的调用会触发该服务上的一个方法,该方法通过回调“ReceiveCustomers”将客户返回给客户端。
话虽这么说,假设我想要 ServiceREST 上的方法“GetSingleCustomer”。假设所有数据都是按需检索的(而不是启动后缓存),我必须首先从 ServiceDuplex 调用“GetCustomers”,并等待我的集合在我实现的回调中填充,然后才能搜索单个客户我需要。
由于 webHttp 不支持对客户端的回调,因此我被迫在 GET (GetSingleCustomer) 调用中使用类似 AutoResetEvent 的内容,直到双工的回调填充集合为止。
对于我想要做的事情是否有一个“最佳实践”,或者我想要做的事情是错误的,以至于还没有创建这样的实践?
感谢您的帮助。
Suppose I wanted to create a WCF WebHTTP service ("ServiceREST") that had a reference to a duplex service ("ServiceDuplex"). ServiceDuplex requires implementations of certain callback members to deliver data that is requested from it. For example, a call to GetCustomers on ServiceDuplex triggers a method on that service that serves the customers back to the client via a callback "ReceiveCustomers".
That being said, suppose I wanted a method "GetSingleCustomer" on ServiceREST. Assuming all data is being retrieved on demand (rather than caching after startup), I'd have to first call "GetCustomers" from ServiceDuplex and wait for my collection to be filled inside of the callback I implement before I can search for the single customer I need.
Since webHttp doesn't support callbacks to the client, I'm forced to use something like an AutoResetEvent inside of my GET (GetSingleCustomer) call until the duplex's callback fills the collection.
Is there a "best practice" for what I'm trying to do, or is what I'm trying to do so wrong that such a practice hasn't been created?!
Thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
保持简单,ServiceDuplex 没有做应该做的事情,比如使调用异步,那么为什么首先使用它......只需坚持只使用 REST。
Keep It Simple, the ServiceDuplex is not doing what is supossed to do, like make the calls Async, then why use it in the first place... just stick to only REST.