首页 > 其他 > 详细

转 the best for wcf client

时间:2016-01-12 11:21:09      阅读:131      评论:0      收藏:0      [点我收藏+]

原文: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));

其他方式自己看原文。

转 the best for wcf client

原文:http://www.cnblogs.com/ly7454/p/5123574.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!