专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Web Service

WCF的ChannelFactory<>CreateChannel(string)有关问题

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
WCF的ChannelFactory<>.CreateChannel(string)问题
protected static TChannel CreateChannel(
      string endpointConfigurationName
  )
  
该方法是一个受保护的方法,在程序里调用就出错误:

IDwgOperation DwgOperationServiceChannel = ChannelFactory<IDwgOperation>.CreateChannel("WpfClientEndpointConfig");

WpfClientEndpointConfig是我的App.config文件里endpoint的name名称。
显示是受保护的方法,那么只有这样:


public static TChannel CreateChannel(
      new NetTcpBing(),
      new EndpointAddress("**************************")
  )

程序中有许多用到createchannet的地方,每用一次就要敲一次地址字符串和new一个bing ,到时改起来也困难,就不能有什么办法指到App.config的配置点读取配置数据吗


------解决思路----------------------
/// <summary>
    /// 通用WCF代理类,继承自ClientBase
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class GeneralClientProxy<T> : System.ServiceModel.ClientBase<T>
        where T:class
    {
        /// <summary>
        /// 采用默认的终结点
        /// </summary>
        public GeneralClientProxy()
        {
        }
        /// <summary>
        /// 使用指定的终结点
        /// </summary>
        /// <param name="endpointConfigurationName"></param>
        public GeneralClientProxy(string endpointConfigurationName) :
            base(endpointConfigurationName)
        {
        }
        /// <summary>
        /// 使用指定的终结点,并使用特定的address
        /// </summary>
        /// <param name="endpointConfigurationName"></param>
        /// <param name="remoteAddress"></param>
        public GeneralClientProxy(string endpointConfigurationName, string remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }
        /// <summary>
        /// 使用指定的目标地址和终结点信息初始化 System.ServiceModel.ClientBase类的新实例
        /// </summary>
        /// <param name="endpointConfigurationName"></param>
        /// <param name="remoteAddress"></param>
        public GeneralClientProxy(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
            base(endpointConfigurationName, remoteAddress)
        {
        }
        /// <summary>
        /// 使用指定的绑定和目标地址初始化 System.ServiceModel.ClientBase类的新实例。
        /// </summary>
        /// <param name="binding"></param>
        /// <param name="remoteAddress"></param>
        public GeneralClientProxy(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
            base(binding, remoteAddress)
        {
        }
        /// <summary>
        /// Gets the inner channel used to send messages to variously configured service endpoints.
        /// </summary>
        public T ClientProxy
        {
            get
            {
                return base.Channel;
            }
        }
    }

我是直接用的ClientBase
------解决思路----------------------
你既然在config文件中配置name为什么不接着把abc三要素全配完,干嘛还要自己去new.在Client节点下面配置endpoint 节点里面abc三要素 其他的配一个默认的就好了, 在用通道工厂完全没有问题,向毛主席保证.
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: