转 the best for wcf client
原文:http://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue/573917#573917
方便使用的一种方式:
public static class MyServiceClientHelp { public static TResult Using<T, TResult>(this T client, Func<T, TResult> work) where T : ICommunicationObject { try { var result = work(client); client.Close(); return result; } catch (Exception e) { client.Abort(); throw; } } }
使用方法:
var result = MyServiceClientHelp.Using (new IntroductionServiceClient(), x => x.IntroduceAsync(new IntroductionRequest { Greeting = "hehhehe", Name = "ly" }).Result ); Console.WriteLine(string.Format("{0} {1}, my name is {2}", result.Greeting, result.ClientName, result.ServiceName));
其他方式自己看原文。
用对方法才有效率,做对事情才有效果
“麻烦”是自己“处理”不当的结果
“困难”是自己“学习”不够的反射
“挫折”是自己“努力”不足的代价
“麻烦”是自己“处理”不当的结果
“困难”是自己“学习”不够的反射
“挫折”是自己“努力”不足的代价