How to Apply a Concurrency Mode to a WCF Service

You can configure the concurrency mode in your WCF service by applying the ServiceBehavior attribute to your service class and then setting the ConcurrencyMode property.

ConcurrencyMode.Single

 

[Visual C#]

[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single)]

public class BankService : IBank

{

    public double Deposit(int accountNo, double depositAmount)          

    {           

        // No risk of corruption.       

    }

}

 

ConcurrencyMode.Reentrant

[Visual C#]

[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant)]

public class BankService : IBank

{

    public double Deposit(int accountNo, double depositAmount)          

    {           

        // Risk of corruption.       

    }

}

 

 

ConcurrencyMode.Multiple

[Visual C#]

[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)]

public class BankService : IBank

{

    public double Deposit(int accountNo, double depositAmount)          

    {           

        // High risk of corruption.       

    }

}

 

 

Tags: