I have written some data fetch service which fetches some entities from main web server, web server delivers the items and client processes the items.
Web Method
[OperationContract]
public DataItem[] GetPendingItems(){
using(DBContext c = new DBContext()){
var q = c.DataItems.Where(x=>x.Attempts<4)
.OrderBy(x=>x.Attempts)
.ThenBy(x=>x.ItemID);
foreach(var item in q){
item.Attempt ++; // making sure item was sent from server
// log what was sent..
}
Utils.Log(DateTime.Now, items);
c.SaveChanges();
return q.ToArray();
}
}
Now similar code on client side has been written in such way..
while(true){
var items = wcfClient.GetPendingItems();
Utils.Log(DateTime.Now, items);
// do something with items..
}
Now here is the problem,
Sent by Server
10:10:10 1,2,3
10:10:11 4,5,6
10:10:11 7,8,9
Received by Client
10:10:10 1,2,3
10:10:11 4,5,6
10:10:11 4,5,6 <-- this is the problem
wcfClient is a global WCF Service Instance Now I know this could be the issue, so we are trying to create new WCFClient instance and trying to see if it works, but if you notice, in my while loop, the calls are completely independent and synchronous.
But looking more closely, this happens rarely, but looks like WCF client returns and old response back to us instead of what it did fetch from server.
Now is there any settings that can explain me why this happens, or why does WCF cache response at all.
We are using latest .NET 4.0 framework on both ends. On an average 2-5% items are missed this way.
I do not have good experience in WCF, but knowing nature of WCF, it should not cache anything at all. Even if it is sending cached response, WCF should not execute method on server.
I assume all are HTTP POST requests as we have chosen BasicHttpBinding.
UPDATE
Changing client code to following resolves the issue,
while(true){
var wcfClient = new WCFClient();
var items = wcfClient.GetPendingItems();
Utils.Log(DateTime.Now, items);
// do something with items..
}
So why does this occur if same client is used?
Changing code to following resolves the issue,
while(true){
var wcfClient = new WCFClient();
var items = wcfClient.GetPendingItems();
Utils.Log(DateTime.Now, items);
// do something with items..
}
Reusing WCFClient (Soap Client Endpoint) causes it to send cached data, even when it should not.