开发者

Silverlight 4 Duplex Service - Stopping the Callback

I have a Silverlight 4 application that uses WCF duplexing by creating a callback to the client. From the client, I have a method that retrieves all rows from a database (not really, but for this 开发者_开发技巧example). Each row is sent to the client using the callback. I need to figure out how to abort this process once started. For example, say I'm tired of seeing all the rows from this table being scrolled by on my screen. I want to see the rows from another table. How do I stop the first action while in the middle of it?

I thought I could just create a new operation on the server to abort processing, but this won't do anything with what's already been sent through the callback and waiting to be picked up by the client.

I am looking for a way to guarantee that once the new search starts, I don't have any old data laying around that will get picked up by the client. Does anyone have any idea on the best way to accomplish this?

It’s funny – before using duplex services, my problem was that I could not get data fast enough. Now that I am using duplexing, I can’t get it turned off!


I can think of two ways to approach this. NB: I haven't tested either, and there are undoubtedly others.

(1) On either the client or the server side, abort the connection and re-establish a new one. Kind of hacky, and I can speak from experience that coding around this sort of "now-you-see-it-now-you-don't" connection is a PITA.

(2) On the server-side, only send a certain amount of data initially, and cache the rest, until you receive a notification from the client that you actually do want to see the next bit. This would resemble the approach used by many "paging" UI's. A variation of this would be to queue not the data, but the calls to the client. Throw them in an Action variable of some sort, queue them up, and only execute the callback once the client has said, "Yup, give me the next 50."

Unfortunately, I don't know of any way to tell the OperationContext, "Abort all the pending calls, but keep the channel alive." Maybe it's there, but I haven't been able to find it. Happy to have someone with more knowledge and experience correct me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜