Czy jest możliwe pozbycie się ogólnego typu TClient w klasie Service

Dla klientów WCF mamIServiceProxyFactory interfejs do ustawiania poświadczeń.

public interface IServiceProxyFactory<T>
{
    T GetServiceProxy();
}

public class ServiceProxy1 : IServiceProxyFactory<ServiceClient1>
{
    public ServiceClient1 GetServiceProxy()
    {
        var client = new ServiceClient1();
        // set credentials here
        return client;
    }
}

public class ServiceProxy2 : IServiceProxyFactory<ServiceClient2> { 
    // ... 
} 

Z pytaniaJakie jest najlepsze obejście problemu z blokowaniem klienta WCF przy użyciu?i stworzyłem pomocnika w następujący sposób:

public static class Service<TProxy, TClient>
    where TProxy : IServiceProxyFactory<TClient>, new()
    where TClient : ICommunicationObject
{
    public static IServiceProxyFactory<TClient> proxy = new TProxy();

    public static void Use(Action<TClient> codeBlock)
    {
        TClient client = default(TClient);
        bool success = false;
        try
        {
            client = proxy.GetServiceProxy();
            codeBlock(client);
            ((ICommunicationObject)client).Close();
            success = true;
        }
        finally
        {
            if (!success)
            {
                ((ICommunicationObject)client).Abort();
            }
        }
    }
}

I używam pomocnika jako:

Service<ServiceProxy1, ServiceClient1>.Use(svc => svc.Method()); 

Pytanie:

Czy jest sposób, w jaki mogę się pozbyćTClient lubTProxy(zaktualizowane) wpisz, aby móc dzwonić za pomocą:

Service<ServiceProxy1>.Use(svc => svc.Method()); 

LUB(zaktualizowane)

Service<ServiceClient1>.Use(svc => svc.Method()); 

Czy jest lepszy sposób niż użycieICommunicationObject dlaClose() iAbort()?

questionAnswers(2)

yourAnswerToTheQuestion