Using Windows Azure AppFabric Service Bus with EPiServer CMS, part 3

This blog post is about registering and calling on-premise services using Windows Azure AppFabric Service Bus from EPiServer CMS. In this series we activate the Service Bus feature of AppFabric, create a WCF REST service, register it on the Service Bus and finally call it from EPiServer CMS.

Introduction

This is the third and final part of the series Using Windows Azure AppFabric Service Bus with EPiServer CMS. Please read part one and part two if you haven’t done so already. In this part we’ll create a very simple plugin to EPiServer CMS which calls the on-premise service using the AppFabric Service Bus.

Creating the plugin

In this exercise I use the AlloyTech sample site from EPiServer. Let’s create a web form page which we’ll use an EPiServer CMS plugin in admin mode. Dan Matthews has a great blog post on a few tips for creating EPiServer CMS plugins.

See sample markup below for our “BizTalk Explorer Services“-plugin.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BizTalkExplorerServicesPlugin.aspx.cs" Inherits="EPiServer.Templates.Advanced.Plugins.BizTalkExplorerServicesPlugin1" %>

<asp:Content ContentPlaceHolderID="MainRegion" runat="server">
    <EPiServerUI:ToolButton ID="btnRefreshApplicationStatus" SkinID="Refresh" Text="Refresh application status" OnClick="btnRefreshApplicationStatus_Click" runat="server" />
    <asp:Label ID="lblApplicationStatus" runat="server"></asp:Label>
</asp:Content>

Let’s dive into the code-behind and implement the logic for calling our service.

namespace EPiServer.Templates.Advanced.Plugins
{
    [GuiPlugIn(
        Area=PlugInArea.AdminMenu,
        DisplayName="BizTalk Explorer Services",
        Url="/Templates/Advanced/Plugins/BizTalkExplorerServicesPlugin.aspx"
        )]
    public partial class BizTalkExplorerServicesPlugin1 : SystemPageBase
    {
        protected override void OnPreInit(EventArgs e)
        {
                base.OnPreInit(e);
                this.MasterPageFile = ResolveUrlFromUI("MasterPages/EPiServerUI.master");
                this.SystemMessageContainer.Heading = "BizTalk Explorer Services on the AppFabric Service Bus";
        }

        protected void btnRefreshApplicationStatus_Click(object sender, EventArgs e)
        {
            using (WebClient client = new WebClient())
            {

                // Get the value from the service using the REST API
                string response = client.DownloadString("https://molniservices.servicebus.windows.net/BizTalkExplorerServices/GetApplicationStatus/1");

                // Parse the XML string response into an XDocument
                XDocument doc = XDocument.Parse(response);

                // Since the value is set at the root we only need to get the value of the root element
                lblApplicationStatus.Text = doc.Root.Value;
            }
        }
    }
}

In the real-world we'd have a more clever way of calling the service, as well as returning the data in JSON-format, but for the sake of this exercise we'll keep it simple.

Testing the plugin

As a final step we test the plugin by logging on to EPiServer CMS and going into admin mode. You’ll find the plugin under Admin, Tools and BizTalk Explorer Services.

image

That’s it! We can now call our on-premise service from EPiServer CMS using the AppFabric Service Bus.

Thanks for reading!

blog comments powered by Disqus