在运行时重新分配客户端端点
我有在后台运行的 C# 应用程序。此应用程序的执行可能需要 1 到 10 分钟,并且从执行开始到执行结束,它都会与调用多个 Web 方法的 WCF 服务进行通信。
为了避免创建/关闭过多的代理对象,我在整个过程期间拥有一个代理对象。我有几个配置了 IIS 的服务器盒,其中有 WCF 服务的副本,我想使用这两个盒来分散负载。由于缺乏昂贵的负载平衡解决方案,我想动态更改代理的端点地址,以便在每个方法调用时与不同的服务器框进行通信。
我在第一个方法调用之前尝试过此操作:
client.Endpoint.Address = new EndpointAddress("http://box1.wcfserviceaddress.com/MyService.svc");
进一步更改此行不会产生任何效果,并且客户端首先连接到的盒子会继续接收方法调用。此外,将服务实例管理从会话更改为每次调用并没有任何区别。
这可以完成还是我需要为每个方法调用创建一个客户端?
问候, F。
I have C# application that runs in the background. The execution of this application can take from 1 to 10 minutes and it's communicating to a WCF service calling multiple web methods from the start until the end of its execution.
To avoid creating/closing too many proxy objects, I've got one proxy object for the duration of the process. I have a couple of server boxes with IIS configured where a copy of the WCF service sits on and I want to use both boxes to spread out the load. For lack of an expensive load balancing solution, I want to change the endpoint address of the proxy on-the-fly to communicate with a different server box per method call.
I've tried this before the first method call:
client.Endpoint.Address = new EndpointAddress("http://box1.wcfserviceaddress.com/MyService.svc");
changing this further down the line won't have any effect and the box the client connected to first keeps receiving the method calls. Also, changing the service instance management from session to per-call doesn't make any difference.
Can this be done or do I need to create a client per method call?
Regards,
F.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该代理派生自实现
ICommunicationObject
的ClientBase
。所有从CommunicationObject
派生或实现ICommunicationObject
的类都具有相同的行为 - 它们只能在Created
状态下进行配置。一旦通信对象从Created
状态移出,配置就无法更改,并且由于首次使用代理后的设置地址(它将状态更改为Opened
),配置也不会更改没有任何影响。获得具有新地址的代理的唯一方法是创建一个新地址。The proxy is derived from
ClientBase
which implementsICommunicationObject
. All classes derived fromCommunicationObject
or implementingICommunicationObject
shares the same behaviour - they can be configured only inCreated
state. Once communication object moves fromCreated
state the configuration cannot be changed and because of that setting address after you use the proxy for the first time (it changes state toOpened
) doesn't have any effect. The only way to get the proxy with a new address is creating a new one.创建并打开客户端后,我 99% 确定(无需再次检查即可 100%)您无法更改其任何 ABC。您将必须为每个服务器完成代理。
Once a client is created and opened, I'm 99% sure (without double-checking to be 100%) that you can't change any of it's ABCs. You're going to have to done proxy per server.