Hi Josh,
It's quite a big topic with different aspects, so not easy to give a quick answer on.
I don't know anything about WCF, and am not sure that's still the way to do things today, unless the back-end or other policy forces that on you.
For getting streaming data into Excel, the abstraction to focus on is the IObservable.
If you can implement a client library that exposes IObservable functions matching the functions you want to call from the worksheet, then the glue to Excel via Excel-DNA is very easy.
So you want some functions that look like this:
public static class LivePricesClient
{
public static IObservable<double> GetLiveSharePrice( string shareCode )
{
// The implementation in here has nothing to do with Excel or Excel-DNA
}
}
Then we'll use some magic glue to make an Excel function like this:
public static class LivePricesExcelFunctions
{
[ExcelFunction("Returns a real-time stream of share prices")]
public static object GetLiveSharePrice( string shareCode )
{
string callerFunctionName = nameof(GetLiveSharePrice);
object[] callerParameters = new object[] { shareCode };
return ObservableRtdUtil.Observe( callerFunctionName, callerParameters,
() => LivePricesClient.GetLiveSharePrice(shareCode) );
}
}
You can define many of these functions in an add-in.
The question now is how to implement the IObservable functions.
It depends a lot on whether you control the back end and protocol.
One approach is to have a list of shareCodes that you are subscribed to (and some API calls to add / remove items from this list).
Your client-side management is then a Dictionary that maps shareCodes to IObservables.
Then when you get called with new data for your subscriptions, you get the matching IObservables and you call OnNext on each of these.
Lifetime management is done in the normal IObservable way - the IObservable's Subscribe function lets you add the shareCode to the list of live ones, and the IDisposable that your Subscribe function returns give you the mechanism
to unsubscribe when a shareCode is no longer used in the sheet.
Nice thing is you can test the whole client (the IObservable parts) without Excel, just in a Console app or in LinqPad script.
With this plan you don't need to pay any attention to recalculation issues, need no other add-in or VBA, and performance should be fine.
-Govert