locked
Share data (list) between clients RRS feed

  • Question

  • People,

    I need develop a WCF to be consumed by workstations using .exe winforms clients (many clients) . This WCF will load a list of products from database and create a list. When a item from this list is requested, by each client (winforms), the  the WCF get a item and, in sequence, remove it from list. 

    In summary: the WCF load 100 products from database. When first client request a item it gets one and remove from list, updating the quantity to 99 items. The second client do a request, and WCF gets another item and the list go to 98 items. When quantity is 0, WCF loads new 100 products. 

    I need share the list between the clients and allow only one per time to call the method "GetNextProduct"

    Currently i do this by database, but is to slower take on per time. 

    Is possible do this with only WCF? Do i need use COM+?

    Thanks.

    Alexandre.

    Alexandre.

    Saturday, March 27, 2010 5:13 PM

Answers

  • To have a singleton, you should decorate your service class with InstanceContextMode.Single, ConcurrencyMode.Single. This way only one client can access you service exclusively.

     

    Regards


    Would you mind marking as answer or vote as helpful, please? It helps getting the network better.

    twitter.com/awerlang
    programmernotfound.blogspot.com
    • Proposed as answer by Haripraghash Sunday, March 28, 2010 1:05 AM
    • Marked as answer by Mog Liang Friday, April 2, 2010 10:33 AM
    Saturday, March 27, 2010 5:55 PM
  • Hi,

    I dont see any reason to think about COM+ here. You need to have a singleton service as metioned by Andre. But beware,If you need multiple clients to access teh servie,all the calls will be blocking until the current call is processed.

    Check this link for more info on instancecontextmode.   http://www.wintellect.com/CS/blogs/jsmith/archive/2006/05/16/instancecontextmode-and-concurrencymode.aspx


    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    • Proposed as answer by Haripraghash Sunday, March 28, 2010 1:05 AM
    • Marked as answer by Mog Liang Friday, April 2, 2010 10:33 AM
    Sunday, March 28, 2010 1:05 AM

All replies

  • To have a singleton, you should decorate your service class with InstanceContextMode.Single, ConcurrencyMode.Single. This way only one client can access you service exclusively.

     

    Regards


    Would you mind marking as answer or vote as helpful, please? It helps getting the network better.

    twitter.com/awerlang
    programmernotfound.blogspot.com
    • Proposed as answer by Haripraghash Sunday, March 28, 2010 1:05 AM
    • Marked as answer by Mog Liang Friday, April 2, 2010 10:33 AM
    Saturday, March 27, 2010 5:55 PM
  • Hi,

    I dont see any reason to think about COM+ here. You need to have a singleton service as metioned by Andre. But beware,If you need multiple clients to access teh servie,all the calls will be blocking until the current call is processed.


    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    Sunday, March 28, 2010 1:05 AM
  • Hi,

    I dont see any reason to think about COM+ here. You need to have a singleton service as metioned by Andre. But beware,If you need multiple clients to access teh servie,all the calls will be blocking until the current call is processed.

    Check this link for more info on instancecontextmode.   http://www.wintellect.com/CS/blogs/jsmith/archive/2006/05/16/instancecontextmode-and-concurrencymode.aspx


    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    • Proposed as answer by Haripraghash Sunday, March 28, 2010 1:05 AM
    • Marked as answer by Mog Liang Friday, April 2, 2010 10:33 AM
    Sunday, March 28, 2010 1:05 AM
  • Hi,

    Thanks for while.

    In summary: I need set the service as InstanceContextMode.Single + ConcurrencyMode.Multiple and use locks to control the access to the list, right?

    Doubt: I must mark my List (ProductLit) as static, or being Single is already always in memory and shared between differents clients?

    Regards.

    Alexandre.

    Thursday, April 1, 2010 12:12 PM
  • Hi,

    Thanks for while.

    In summary: I need set the service as InstanceContextMode.Single + ConcurrencyMode.Multiple and use locks to control the access to the list, right?

    Doubt: I must mark my List (ProductLit) as static, or being Single is already always in memory and shared between differents clients?

    Regards.

    Alexandre.

    Use static or Single instanceContext mode would do the job. However, please note that store in memory is not safe. Use database may be slow, but it would prevent data from losing.

    Thanks,


    Mog Liang
    Friday, April 2, 2010 10:32 AM