.net - 客户端如何使用负载平衡的WCF服务

标签 .net wcf

我有一个在负载平衡场景中托管的 WCF 服务。该服务使用 IIS 托管。有两台负载均衡的服务器。

以下是服务器中的端点https://labA.myCompany.com:44330/MyService/InternalService.svc https://labB.myCompany.com:44330/MyService/InternalService.svc

我将主机基地址保留为

baseAddress=" https://test-LoadBalanced.myCompany.com/MyService". 

该主机基地址来自负载均衡地址。

当我输入https://test-LoadBalanced.myCompany.com/MyService/InternalService.svc时我可以获取服务页面。在其中,有时我会获得 ServerA 框的端点地址的 wsdl 链接,有时会获得 Server B 框的端点地址的 wsdl 链接。

引用

问题的答案WCF Service Endpoints vs Host Base address

When you host the WCF service on IIS, the base address can only be the URL to the .svc file.

以下内容来自WCF Addressing In Depth

Clients have no awareness of the service’s base address and have no need to support something similar on their side of the wire. As a result, you won’t find anything related to base addresses in the client-side object model or the configuration section. Clients simply choose a particular endpoint, which always comes configured with an absolute address, and that absolute address determines the address it will use during transmission.

来自Load Balancing

By default, the BasicHttpBinding sends a connection HTTP header in messages with a Keep-Alive value, which enables clients to establish persistent connections to the services that support them. This configuration offers enhanced throughput because previously established connections can be reused to send subsequent messages to the same server. However, connection reuse may cause clients to become strongly associated to a specific server within the load-balanced farm, which reduces the effectiveness of round-robin load balancing. If this behavior is undesirable, HTTP Keep-Alive can be disabled on the server using the KeepAliveEnabled property with a CustomBinding or user-defined Binding.

客户端

我使用负载平衡地址创建了一个客户端。然而,在客户端配置中,端点地址是服务器A盒子的地址;不是负载均衡地址。

问题

那么,客户端如何利用负载均衡的性能优势呢?它总是会访问服务器A来获取服务操作,不是吗?

最佳答案

更改客户端的代码/配置以指向服务的负载平衡端点。

基地址仅是服务器关心的问题。它为您提供了一种指定所有其他相对 URI 所基于的基本 URI 的方法。

如果您的客户端向负载均衡器发送 HTTP 消息,它们将被转发到服务器。为此,只需使用服务的负载均衡器配置您的客户端即可。

在服务器上也禁用 HTTP keep-alive 可能也是明智之举,以防止您的客户端与 LB 后面的服务器形成粘性关系。

关于.net - 客户端如何使用负载平衡的WCF服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15434039/

相关文章:

c# - WCF REST 网络服务 : getting request data when the content is not xml valid

.net - WCF ExceptionShielding 错误 ID 与传递给处理程序的 HandlingInstanceId 不匹配

c# - 在 String.Format 中转义大括号 '{'

c# - 如何在c#中等待事件被处理

c# - 将文件从 PC 复制到 Windows Mobile 设备的好方法是什么?

c# - DbContext 在传递到另一个 `using` block 时过早处置

c# - 关闭客户端应用程序: existing connection was forcibly closed by the remote host时在服务器上记录ServiceModel错误

.net - 具有多个 Order By 子句的 Linq 语句不起作用

.net - 将 OperationContext 保存在任务并行库中

wcf - 消息响应僵尸发生,错误代码为 0xC0C01B4C 和 0xc0c016b5 无编排