Hi.
I have a question regarding use of interfaces when unmanaged resources come to play. Suppose I have a web service and generated WCF client. Service contract looks like this:
[ServiceContract]
public interface ITestService
{
[OperationContract]
string GetData(int value);
}
On client side I use dependency injection and bind ITestService interface to TestServiceClient (generated with svcutil). However, when I create ITestService and it really is TestServiceClient it should be disposed in correct way but the clients don't know about it. How do you deal with this problem?
I thought about generating proxy classes like this:
class TestServiceClientProxy : ITestService
{
#region ITestService Members
public string GetData(int value)
{
var client = new TestServiceClient();
bool success = false;
try
{
var result = client.GetData(value);
client.Close();
success = true;
return result;
}
finally
{
if (!success)
{
client.Abort();
}
}
}
#endregion
}
However, I don't think code generation would be best way to go. Should I use some AOP framework or DynamicProxy?
Thanks in advance for help.