[英]WCF - Create client programmatically only from endpoint name
My WCF client can connect to several endpoints. 我的WCF客户端可以连接到多个端点。 But they all have different addresses, bindings and contracts.
但是它们都有不同的地址,绑定和合同。 So my question is : How can I create my WCF client programmatically depending just of the name of my endpoint I want to connect to (which I have in my code)
所以我的问题是:如何仅依靠要连接的端点名称(我在代码中拥有)来以编程方式创建WCF客户端
If I understood your question correctly, I believe this is the answer [using IPC, can be easily converted to other communication types] 如果我正确理解了您的问题,我相信这就是答案[使用IPC,可以轻松转换为其他通信类型]
Listener: 听众:
_host = new ServiceHost(typeof(ContractClass));
_host.AddServiceEndpoint(typeof(IContract), new NetNamedPipeBinding(), new Uri("net.pipe://localhost/" + listenerEndpointName));
_host.Open();
Client: 客户:
var factory = new ChannelFactory<IContract>(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/" + listenerEndpointName));
IContract proxy = factory.CreateChannel();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.