2
This answer發佈的響應式爲this question。WCF代理使用情況
它現在有點高於我的頭,但是應該在客戶端代理類中使用「高階函數」嗎?這是正確的用法嗎?:
public class MyProxy
{
readonly IMyService service =
new ChannelFactory<IMyService>("IMyService").CreateChannel();
public ResponseObject Foo(RequestObject request)
{
return UseService((IMyService service) =>
service.Bar(request));
}
T UseService<T>(Func<IIssueTrackerService, T> code)
{
bool error = true;
try
{
T result = code(issueTrackerChannel);
((IClientChannel)issueTrackerChannel).Close();
error = false;
return result;
}
finally
{
if (error)
{
((IClientChannel)issueTrackerChannel).Abort();
}
}
}
}
我真的很想找的是一些指導,這是正確的方法來做到這一點。