views:

12

answers:

1

Hi, I am new to wcf and I have written a wcf web service that performs operations on database like an update. The service is consumed by silverlight clients. When multiple users try to make certain change to an object, I want the wcf service to manage it. e.g. if a certain object is acknowledged(update operation in db) by one user, another user must not be allowed to perform the same operation on it. I dunno how synchronization can be implemented in WCF.

Please help thanx

A: 

Hello,

your synchronization is called concurrency problem and such problem has to be performed in database. I guess that each RDMS (relation database management system) has special type for row version which is used to handle optimistic concurrency. Row version column has special meaning, you can't set its value but the RDMS changes its value each time the record is modified. SQL server offers row version in Timestamp data type.

To use optimistic concurrency you need to add timestamp column to each table where you want to handle it. Then you have to use this column. You have to load it with each record and each update / delete has to use its value in WHERE clause. Then you have to test number of affecter records to know if the update / delete was successful and handle unsuccessful modification. This is general approach if you use DbCommand and DbDataReader related classed directly. LinqToSql, DataSets and Entity framework have same level of support for optimistic concurrency handling.

Btw. it is possible to use optimistic concurrency without Timestamp column but in that case you have to store updated values together with old values and then use old values in WHERE clause in update command.

Best regards, Ladislav

Ladislav Mrnka