DCSIMG
WCF Practices: Writing single function for your entire WCF proxy calls - Rotem Bloom's Blog

Rotem Bloom's Blog

Share knowledge on .NET and web development

News

About Me

Glad to help and share knowledge on .NET and also huge fan of Dream Theater.

Contact me via messenger

View Rotem Bloom's profile on LinkedIn

Dream Theater Pics

Blogs I Read

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;

}

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: