zoukankan      html  css  js  c++  java
  • WCF 客户端调用封装

       public static void Invoke<TChannel>(Action<TChannel> action, TChannel proxy)
            {
                ICommunicationObject channel = proxy as ICommunicationObject;
                if (null == channel)
                {
                    throw new ArgumentException("The proxy is not a valid channel implementing the ICommunicationObject interface", "proxy");
                }
                try
                {
                    action(proxy);
                }
    
                catch (TimeoutException)
                {
                    channel.Abort();
                    throw;
                }
    
                catch (CommunicationException)
                {
                    channel.Abort();
                    throw;
                }
                finally
                {
                    channel.Close();
                }
            }
    
            public static TReturn Invoke<TChannel, TReturn>(Func<TChannel, TReturn> func, TChannel proxy)
            {
                ICommunicationObject channel = proxy as ICommunicationObject;
                if (null == channel)
                {
                    throw new ArgumentException("The proxy is not a valid channel implementing the ICommunicationObject interface", "proxy");
                }
                try
                {
                    return func(proxy);
    
                }
    
                catch (TimeoutException)
                {
                    channel.Abort();
                    throw;
                }
    
                catch (CommunicationException)
                {
                    channel.Abort();
                    throw;
                }
                finally
                {
                    channel.Close();
                }
            }
    

     服务方式不能包含ref和out参数,因为这两种类型的参数不能作为匿名方法的参数。

  • 相关阅读:
    js实现输入银行卡号隔四位添加一个空格
    写出优雅的代码
    FOJ Problem 1016 无归之室
    FOJ Problem 1015 土地划分
    大数相加减
    NYOJ 42 一笔画
    NYOJ36 水池数目
    NYOJ 32 组合数
    贪吃蛇StringBuilder 和 定时器
    星 辰 · 第 三 条 约 定
  • 原文地址:https://www.cnblogs.com/wonderfuly/p/8443877.html
Copyright © 2011-2022 走看看