I have a C# client implementing System.ServiceModel.ClientBase<TChannel>
for communication with a SOAP API.
I want the client to automatically retry requests when timeouts occur.
I figure I could use a library like Polly to create an HttpClient instance with a retry policy.
However, I can't work out how to instantiate the WCF client with that HttpClient.
I'm also not sure if I'm meant to be using a different approach altogether, like creating a IEndpointBehavior
.
It looks like there is a CreateChannel
instance method that can be overridden and a ConfigureEndpoint
static partial method that can be implemented, but I cant find any examples of how to use them correctly to implement retry either by using an instantiated HttpClient or via some other mechanism.
I've searched through the docs for building clients. There are sections on using channel factories, but it also doesn't seem to have a mechanism of supplying an HttpClient.
The docs for expected exceptions specifically mention TimeoutException
, but the example just try/catches calls on the client.
I don't really want to do RetryOnTimeout(client => client.MethodToRetryOnTimeout());
. I know I can do that, and I know I can create a decorator that wraps all the client calls in similar logic. I just don't think that's the right approach.
Any help pointing me in the right direction would be appreciated.