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参数,因为这两种类型的参数不能作为匿名方法的参数。

  • 相关阅读:
    预定义规则 取范围数据
    oracle table 数组的赋值方法
    java 缓存读写
    webpack
    vscode setting
    webpack babel
    共享你的vscode配置
    github API很丰富
    tips
    todo
  • 原文地址:https://www.cnblogs.com/wonderfuly/p/8443877.html
Copyright © 2011-2022 走看看