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三要素 其他的配一个默认的就好了, 在用通道工厂完全没有问题,向毛主席保证.