WCF Practices: Writing single function for your entire WCF proxy calls
Let's say you want that all your WCF proxy calls will come from one function. This could be very useful and save a lot of code.
For example you can write your proxy exception handling in one place.
Here is the code example that work on .NET framework 3.5 only:
// The public function that execute the WCF proxy call
public void WCFProxyCall()
{
CreateConferenceRequest r = new CreateConferenceRequest();
Func createFunc = a => proxy.CreateConference(a);
CreateConferenceResponse ci = ProxyWrapperOperation(createFunc, r);
}
// This is the single point function for the entire WCF proxy calls
// Here you can write code for all your WCF proxy calls.
private TResult ProxyWrapperOperation(Func operation, T parameter)
{
TResult result;
try
{
result = operation(parameter);
}
catch (TimeoutException timeProblem)
{
proxy.Abort();
throw;
}
catch (FaultException unknownFault)
{
throw;
}
catch (CommunicationException commProblem)
{
proxy.Abort();
throw;
}
return result;
}