I have a Silverlight client using MEF/Prism that connects to a WCF service. I am writing a “service agent” to use as a shared service throughout the application. This “service agent” is a singleton that provides the only way for the client to call the WCF service. I’ve implemented my service contract and all of the methods look very similar, except for the specific Begin/End operations they call and the arguments they accept.
For example:
public void WakeUpInstanceAsync(Foo opportunity, bool isHistorical, Action<WakeupObj> callback)
{
if (IsOpen())
{
AsyncCallback asyncCallback = (e) =>
{
_currentDispatcher.BeginInvoke(() =>
{
try
{
callback(_funnelClient.EndWakeUpInstance(e));
}
catch (CommunicationException ex1)
{
// Notify someone via eventaggregator?
callback(null);
}
});
};
_funnelClient.BeginWakeUpInstance(opportunity, isHistorical, asyncCallback, null);
}
}
Is there any way I could create a generic method that takes a 2 parameters (the “begin” method and the “end” method)?
Would something like this be what you are looking for?
(disclaimer – I have not compiled it)