开发者

C# Web Service Mutual Exclusion

elI have two types of nodes. One is a coordinator 开发者_运维知识库and another is a worker node.

They communicate through SOAP.

All worker nodes send requests to the coordinator for a mutually exclusive database record.

I want the coordinator to return the ID of a safe record to each worker so no worker has the same record to process.

I know how to do something similar with threads in C# using mutex, but I wanted to know the best practice for synchronous web service calls.

EDIT: heres the problem I have

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;
    }
}


I had a similar type of issue that I resolved at the database level:

  1. assign each worker a unique identifier
  2. when asking for a record from the coordinator the workers would transmit their identifier
  3. the DB routine was a stored procedure that started by acquiring an application lock (SQL Server)
  4. I would then look for a "free" record, then "stamp it" with the worker identifier so we know it's locked and by whom
  5. return the record to the worker
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜