tags:

views:

52

answers:

2

As of now, I am thinking of keeping data in a DataSet in a WCF hosted service and other apps(on same box) can access the data via Named Pipes(exposed through WCF service). The apps then keep a copy of dataSet inside them so as to not re-fetch the data from the WCF unless it gets changed.

Is there a better way to achieve this ?

Some other details -

  1. Data is retrieved from the server in form of datarows collection, so I am writing it as DataTables and storing it as Dataset.
  2. Data will rarely change but when it does I have to inform all client apps which had retrieved the data to refresh up.

Thanks! Amit

A: 

Your solution would work. If you have access to a proper cache service, like ScaleOut StateServer, Velocity, or memcached, you could use it for your needs. It would be doing much the same thing, but you would be getting a proven solution with additional features surrounding cache management, as well the ability to scale to more than a single machine should the need arise.

ssmith
A: 

I do something similar with an app I wrote.

You can easily let the service update the clients when the data changes by using a callback. When a clients connects to the service you will need to store their callback info and when the data is updated you just fire off the message to each subscribed clients.

Here is the contract for the callback:

public interface IServiceMessageCallback
{

    [OperationContract(IsOneWay = true)]
    void OnReceivedServiceMessage(ServiceMessage serviceMessage);
}

The service implements this interface. The service has this private field:

    /// <summary>
    /// Holds the callback recipients
    /// </summary>
    private List<IServiceMessageCallback> callbackMessages = 
              new List<IServiceMessageCallback>();

When the clients connects do something like this:

    IServiceMessageCallback callback = 
       OperationContext.Current.GetCallbackChannel<IServiceMessageCallback>();
    callbackMessages.Add(callback);

And finally, whatever method you have that updates the data on the service should also have this:

    Action<IServiceMessageCallback> fire =
         delegate(IServiceMessageCallback callback)
             { callback.OnReceivedServiceMessage(serviceMessage); };

    // loop thru the callback channels and perform the action
    callbackMessages.ForEach(fire);

I sort of patched this code together from a rather hefty service I wrote... hopefully the pieces make sense out of context.

Sailing Judo
Thanks a ton Judo, this really helps!