elI 有两种类型的节点。一个是协调器,另一个是工作节点。
它们通过 SOAP 进行通信。
所有工作节点都向协调器发送请求以获得互斥的数据库记录。
我希望协调员将安全记录的 ID 返回给每个工作人员,这样没有工作人员需要处理相同的记录。
我知道如何使用互斥锁对 C# 中的线程做类似的事情,但我想知道同步 Web 服务调用的最佳实践。
编辑:这是我遇到的问题
public class Coordinator: System.Web.Services.WebService
{
[WebMethod]
//Returns a mutually record to worker nodes
public int RequestRecordID()
{
//i want to lock here
int id = repository.getFirst(el => el.locked==false);
repository.getByID(id).locked = true;
repository.save();
//unlock here
return id;
}
}