在Silverlight中删除过时的WCF响应

时间:2021-05-21 02:57:11

In Silverlight I got the following problem. If you fire multiple requests to the web service, the responses might not return in an ordered sequence. Meaning if the first request takes longer than the following ones, its response will return at last:

在Silverlight中,我遇到了以下问题。如果向Web服务发出多个请求,则响应可能不会按顺序返回。意思是如果第一个请求比下面的请求花费更长时间,它的响应将最后返回:

1. Sending request A.. (takes longer for some reason)
2. Sending request B..
3. Sending request C..
4. ...
5. Receiving response B
6. Receiving response C
7. Receiving response A

Now in my scenario, I am only interested in the most recent request being made. So A and B should be discareded and C should be kept as only accepted response.

现在在我的场景中,我只对最近提出的请求感兴趣。因此应该删除A和B,并且应该将C保留为仅接受的响应。

What is the best approach to manage this? I came up with this solution so far:

管理这个的最佳方法是什么?到目前为止我想出了这个解决方案:

Pass a generated GUID as user object when sending the request and store that value somewhere. As all responses will contain their respective GUID, you can now filter out the stale responses. A request-counter instead of a GUID would work as well.

在发送请求时将生成的GUID作为用户对象传递,并将该值存储在某处。由于所有响应都将包含各自的GUID,因此您现在可以过滤掉过时的响应。请求计数器而不是GUID也可以。

Now I wonder if there are any better approaches to this. Maybe there are any out of the box features to make this possible? Any ideas are welcome..

现在我想知道是否有更好的方法。也许有任何开箱即用的功能使这成为可能吗?欢迎任何想法..

2 个解决方案

#1


I take a similar approach in my non-WCF ASP.NET web services, though I use the DateTime of the request instead and then just store the DateTime of the most recent request. This way I can do a direct less than comparison to determine if the returning service is the most recent or not.

我在非WCF ASP.NET Web服务中采用了类似的方法,但我使用了请求的DateTime,然后只存储了最新请求的DateTime。通过这种方式,我可以直接进行比较,以确定返回的服务是否是最新的。

I did look into canceling old service calls before making new ones, but there is no CancelAsync call for web services in Silverlight and I have been unable to find an equivalent way of doing this.

我确实在创建新服务之前取消了旧服务调用,但Silverlight中没有对Web服务的CancelAsync调用,而且我无法找到相同的方法来执行此操作。

#2


Both of these approaches are what I took when I worked on a real time system with a lot of service calls. Basically just have some way to keep track of order ( incrementing variable, timestamp, etc. ) then keep track of highest received response. If the current response is lower than the highest, drop it.

这两种方法都是我在使用大量服务调用的实时系统上工作时所采用的方法。基本上只是有一些方法来跟踪顺序(递增变量,时间戳等),然后跟踪最高接收响应。如果当前响应低于最高响应,则将其丢弃。

#1


I take a similar approach in my non-WCF ASP.NET web services, though I use the DateTime of the request instead and then just store the DateTime of the most recent request. This way I can do a direct less than comparison to determine if the returning service is the most recent or not.

我在非WCF ASP.NET Web服务中采用了类似的方法,但我使用了请求的DateTime,然后只存储了最新请求的DateTime。通过这种方式,我可以直接进行比较,以确定返回的服务是否是最新的。

I did look into canceling old service calls before making new ones, but there is no CancelAsync call for web services in Silverlight and I have been unable to find an equivalent way of doing this.

我确实在创建新服务之前取消了旧服务调用,但Silverlight中没有对Web服务的CancelAsync调用,而且我无法找到相同的方法来执行此操作。

#2


Both of these approaches are what I took when I worked on a real time system with a lot of service calls. Basically just have some way to keep track of order ( incrementing variable, timestamp, etc. ) then keep track of highest received response. If the current response is lower than the highest, drop it.

这两种方法都是我在使用大量服务调用的实时系统上工作时所采用的方法。基本上只是有一些方法来跟踪顺序(递增变量,时间戳等),然后跟踪最高接收响应。如果当前响应低于最高响应,则将其丢弃。