我有一个 WCF 服务,它的一些操作可能需要很长时间......客户端收到 TimeoutException,但服务器在长时间操作后继续执行。
服务器:
public void doSomeWork(TransmissionObject o) {
doDBOperation1(o); //
doDBOperation2(o); // may result in TimeoutException on client
doDBOperation3(o); // it continues doing DB operations. The client is unaware!
}
客户:
ServiceReference.IServiceClient cli = new ServiceReference.IServiceClient("WSHttpBinding_IService","http://localhost:3237/Test/service.svc");
int size = 1000;
Boolean done = false;
TransmissionObject o = null;
while(!done) {
o = createTransmissionObject(size);
try {
cli.doSomeWork(o);
done = true;
}catch(TimeoutException ex) {
// We want to reduce the size of the object, and try again
size--;
// the DB operations in server succeed, but the client doesn't know
// this makes errors.
}catch(Exception ex) { ... }
}
由于服务器正在执行一些数据库操作,我需要检测服务器端的超时才能回滚数据库操作。
我尝试在客户端使用带有 [TransactionFlow]、TransactionScope 等的事务,但是服务器上的数据库操作使用的是嵌套的存储过程!!,因此我不能使用分布式事务。(我收到一个 SqlException 说:不能在分布式事务中使用 SAVE TRANSACTION。)。如果我使用简单的 SP(不是嵌套的),那么带有事务的解决方案可以正常工作。
我的问题:如何检测 TimeoutException,但在服务器端?我猜是与代理状态有关的东西......或者可能是一些可以被服务器捕获的事件。我不确定在服务器端处理事务是否是正确的解决方案。是否有解决此问题的模式?
谢谢!