zoukankan      html  css  js  c++  java
  • 转 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));

    其他方式自己看原文。

  • 相关阅读:
    最少必要知识
    pythonGUI编程
    计算机网络基础
    .htaccess总结
    SSRF总结
    jsp学习笔记
    url任意跳转漏洞
    学期总结
    计科一班本学期作业成绩汇总表格
    C语言I博客作业08
  • 原文地址:https://www.cnblogs.com/ly7454/p/5123574.html
Copyright © 2011-2022 走看看