Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

A reliable .NET wrapper around a WCF ClientBase that provides seamless retrying and transient fault handling

License

Notifications You must be signed in to change notification settings

evan-rash/ReliableWcfService

Repository files navigation

ReliableWcfService

A reliable wrapper around a WCF client proxy that provides seamless retrying, transient fault handling, and automatically closes or aborts the proxy as appropriate.

To use the ReliableWcfService, simply derive from the abstract ReliableWcfService class

public class DemoWcfService : System.ServiceModel.ReliableWcfService<ServiceReference1.IDemoService>
{
    protected override System.ServiceModel.ICommunicationObject CreateClientBase()
    {
        return new ServiceReference1.DemoServiceClient();
    }
}

Now you can host calls to the DemoService proxy within the DemoWcfService:

DemoWcfService demoService = new DemoWcfService();
string sampleData = await demoService.GetAsync(proxy => proxy.GetSampleDataAsync());

Transient Fault Handling & Retrying

WCF service proxies throw many different types of transient errors. ReliableWcfService automatically catches these transient exceptions and transparently retries.

  • FaultException
  • ChannelTerminatedException
  • EndpointNotFoundException
  • ServerTooBusyException
  • TimeoutException

Automatically Closing & Aborting Proxies

WCF service proxies don't support the standard using() pattern. ReliableWcfService handles all of this for you!

The following vanilla WCF code will fail:

using (var proxy = new ServiceReference1.DemoServiceClient())
{
  string data = await proxy.GetSampleDataAsync();
}

Instead, you have to manually call Close() and Abort(), which adds unnecessary boilerplate:

var proxy = new ServiceReference1.DemoServiceClient();
try
{
  string data = await proxy.GetSampleDataAsync();
  proxy.Close();
}
catch(CommunicationException)
{
    proxy.Abort();
}
catch (TimeoutException)
{
    proxy.Abort();
}

About

A reliable .NET wrapper around a WCF ClientBase that provides seamless retrying and transient fault handling

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages