I have following wrapper to help me manage the wcf client lifetime:
public class ServiceProxyHelper<TProxy, TChannel> : IDisposable
where TProxy : ClientBase<TChannel>, new()
where TChannel : class
{
private TProxy m_proxy;
public TProxy Proxy
{
get
{
if (m_proxy != null)
{
return m_proxy;
}
throw new ObjectDisposedException("ServiceProxyHelper");
}
}
protected ServiceProxyHelper()
{
m_proxy = new TProxy();
}
public void Dispose()
{
//....
}
}
I’m using that in the following way:
public class AccountServiceClientWrapper : ServiceProxyHelper<AccountServiceClient, IAccountService>
{
}
public class Test()
{
using(AccountServiceClientWrapper wrapper = new AccountServiceClientWrapper())
{
wrapper.Proxy.Authenticate();
}
}
How I can modify that code to provide endpointConfigurationName for the client ?
wrapper.Proxy.Endpoint.Name = "MyCustomEndpointName";
Is not working. That endpointConfigurationName should be provider to service client constructor, but how I can do that using this wrapper ?
Regards
Perhaps you can use Activator.CreateInstance to create the proxy instance passing endpointConfigurationName as a parameter. For example,
This will be an additional constructor in your wrapper to allow passing end point config name. Only flaw would be in case proxy type does not support such constructor, you will get an runtime exception instead of compile time error.