Share via


Implementing Load Balancing

Applies to: SharePoint Foundation 2010

Service Application Framework applications are typically hosted on multiple computers and invoked from service client applications running on front-end Web servers. You must route service application proxy method invocations from the front-end Web server to an appropriate application server by using a load balancer.

SharePoint 2010 provides a simple load balancer implementation in the SPRoundRobinServiceLoadBalancer class. Service application proxies can use the built-in load balancer to route requests to the appropriate back-end service application.

Creating, Provisioning, and Unprovisioning the Load Balancer

The following example code shows how to create, provision, and unprovision (remove provisioning from) the load balancer.

internal SampleWebServiceApplicationProxy(
   string name,
   SampleWebServiceProxy serviceProxy,
   Uri serviceApplicationAddress)
   : base(name, serviceProxy, serviceApplicationAddress)
        {
   // Create a new load balancer.
   m_LoadBalancer = new SPRoundRobinServiceLoadBalancer(serviceApplicationAddress);
   
        }

        public override void Provision()
        {
   // Provision the load balancer.
   m_LoadBalancer.Provision();

   base.Provision();
 
   // Ensure the provisioned load balancer 
   // is persisted back to the database.  
   this.Update();
        }

        public override void Unprovision()
        {
   // Unprovision the load balancer.
   m_LoadBalancer.Unprovision();

   base.Unprovision();

   // Ensure the unprovisioned load balancer 
   // is persisted back to the database.  
   this.Update();
        }
Friend Sub New(ByVal name As String, ByVal serviceProxy As SampleWebServiceProxy, ByVal serviceApplicationAddress As Uri)
    MyBase.New(name, serviceProxy, serviceApplicationAddress)
    ' Create a load balancer.
    m_LoadBalancer = New SPRoundRobinServiceLoadBalancer(serviceApplicationAddress)

End Sub

Public Overrides Sub Provision()
    ' Provision the load balancer.
    m_LoadBalancer.Provision()

    MyBase.Provision()

    ' Ensure the provisioned load balancer 
    ' is persisted back to the database.  
    Me.Update()
End Sub

Public Overrides Sub Unprovision()
    ' Unprovision the load balancer.
    m_LoadBalancer.Unprovision()

    MyBase.Unprovision()

    ' Ensure the unprovisioned load balancer 
    ' is persisted back to the database.  
    Me.Update()
End Sub

See Also

Reference

SPRoundRobinServiceLoadBalancer