简体   繁体   English

如何配置客户端以连接到相同接口但作用域不同的两个WCF服务器端点?

[英]How to configure a client to connect to two WCF server endpoints of the same interface but in different scope?

I have a service that programmatically creates two net-tcp end points of the same interface but in different scope (they do different things under the hood). 我有一项服务,该服务以编程方式创建了同一接口但在不同范围内的两个net-tcp端点(它们在后台执行不同的操作)。 Normally when services run as they are supposed to, there is no problem for a client service to discover these two points properly based on the scope of each of them. 通常,当服务按预期运行时,客户端服务不会根据它们各自的范围正确发现这两点。 However since discovery doesn't work across subnets, when testing I usually add manual configuration into my app.config to enable my app successfully register endpoints even if discovery fails (which does). 但是,由于发现无法跨子网工作,因此在测试时,我通常将手动配置添加到我的app.config中,以使我的应用程序即使发现失败也能成功注册端点(这样做)。 Now how can I configure my app.config so that it would work for my new endpoints? 现在如何配置我的app.config,使其适用于新端点?

<?xml  version="1.0"?>
<configuration>
    <system.serviceModel>
        <client>
            <endpoint
                address="net.tcp://myserver:2170/"
                binding="netTcpBinding"
                contract="IMyServiceInterface"
                name="Service1"/>
            <endpoint
                address="net.tcp://myserver:2173/"
                binding="netTcpBinding"
                contract="IMyServiceInterface"
                name="Service2"/>
        </client>
    </system.serviceModel>
</configuration>

What if you try to make service clients with this constructor dynamically 如果尝试使用此构造函数动态创建服务客户端该怎么办

public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) 

and push different settings manually. 并手动推送其他设置。

Not sure what exactly is your problem in. I don't see why you look into interfaces on client side, since behavior should be defined on server. 不知道问题出在什么地方。我不明白为什么要研究客户端的接口,因为行为应该在服务器上定义。 As per my understanding, you just need to generate your client class once (it's being done automaticaly by VS) and to use it's constructor like that: 根据我的理解,您只需要生成一次客户端类(它由VS自动完成)并使用如下的构造函数:

var remoteAddr = "net.tcp://myserver:2173/";
var client = new MyClient("*",remoteAddr);

in your app.config there will be only one configuration, pointing to some default server. 在您的app.config中,只有一种配置,指向某个默认服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM