在运行时重新分配客户端端点

发布于 2024-11-15 23:07:13 字数 506 浏览 5 评论 0原文

我有在后台运行的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜光 2024-11-22 23:07:13

该代理派生自实现ICommunicationObjectClientBase。所有从 CommunicationObject 派生或实现 ICommunicationObject 的类都具有相同的行为 - 它们只能在 Created 状态下进行配置。一旦通信对象从 Created 状态移出,配置就无法更改,并且由于首次使用代理后的设置地址(它将状态更改为 Opened),配置也不会更改没有任何影响。获得具有新地址的代理的唯一方法是创建一个新地址。

The proxy is derived from ClientBase which implements ICommunicationObject. All classes derived from CommunicationObject or implementing ICommunicationObject shares the same behaviour - they can be configured only in Created state. Once communication object moves from Created state the configuration cannot be changed and because of that setting address after you use the proxy for the first time (it changes state to Opened) doesn't have any effect. The only way to get the proxy with a new address is creating a new one.

笑饮青盏花 2024-11-22 23:07:13

创建并打开客户端后,我 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文