How to leverage the internal HTTP endpoint available on Azure web roles?

Posted by adelsors on Geeks with Blogs See other posts from Geeks with Blogs or by adelsors
Published on Fri, 07 Jan 2011 12:43:43 GMT Indexed on 2011/01/07 12:54 UTC
Read the original article Hit count: 175

Filed under:

Imagine you have a Web application using an in-memory collection that changes occasionally, loading it from storage on the Application_Start global.asax event and updating it whenever it changes.

If you want to deploy this application on Azure you need to keep in mind that more than one instance of the application can be running at any time and therefore you need to provide some mechanism to keep all instances informed with the latest changes.

Because that the communication through internal endpoints between Azure role instances is at no cost, a good solution can be maintaining the information on Azure Storage Tables, reading its contents on the Application_Start event and populating its changes to all instances using the internal HTTP port available on Azure Web Roles.

You need to follow these steps to leverage the internal HTTP endpoint available on Azure web roles:

1.   Define an internal HTTP endpoint in the Web Role properties, for example InternalHttpEndpoint

 

2.   Add a new WCF service to the Web Role, for example NotificationServices.svc

3.   Add a method on the new service to receive notifications from other role instances.

4.   Declare a class that inherits from System.ServiceModel.Activation.ServiceHostFactory and override the method CreateServiceHost to host the internal endpoint.

 

Note that you can use SecurityMode.None because the internal endpoint is private to the instances of the service, this is provided by the platform.

5.   Edit the markup of the service right clicking the svc file and selecting "View markup" to add the new factory as the factory to be used to create the service

 

 6. Now you can notify changes to other instances using this code:

© Geeks with Blogs or respective owner