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 second part of the series Using Windows Azure AppFabric Service Bus with EPiServer CMS. Please read part one if you haven’t done so already. In this part we create a WCF REST service and register it on the AppFabric Service Bus.
Prerequisites
Creating the WCF REST service
Create a WCF Service Library. In this demo I’ll be using DBLOG.BizTalk.ExplorerServices to simulate integration with on-premise BizTalk Server services together with EPiServer CMS.

By default the Target framework is set to .NET Framework Client Profile. Change this by right clicking the project, selecting Application and setting the Target framework to .NET Framework 4.
![2.-Set-Target-framework-to-.NET-Fram[1] 2.-Set-Target-framework-to-.NET-Fram[1]](http://blog.bergdaniel.se/image.axd?picture=2.-Set-Target-framework-to-.NET-Fram%5B1%5D_thumb_1.png)
Add a reference to System.ServiceModel.Web.
![3.-Add-reference-to-System.ServiceMo[2] 3.-Add-reference-to-System.ServiceMo[2]](http://blog.bergdaniel.se/image.axd?picture=3.-Add-reference-to-System.ServiceMo%5B2%5D_thumb_1.png)
Rename IService1 and Service1. In this demo I’ll be using IBtsApplication and BtsApplication. See sample code below. I’ve left out using-statements for brevity.
namespace DBLOG.BizTalk.ExplorerServices
{
[ServiceContract]
public interface IBtsApplication
{
[OperationContract, WebGet(UriTemplate="GetApplicationStatus/{applicationId}")]
string GetApplicationStatus(string applicationid);
}
}
namespace DBLOG.BizTalk.ExplorerServices
{
[ServiceBehavior]
public class BtsApplication : IBtsApplication
{
/// <summary>
/// Get status of BizTalk application
/// </summary>
/// <param name="applicationId">BizTalk application ID</param>
public string GetApplicationStatus(string applicationId)
{
return string.Format("Application with ID {0} is OK at {1}",
applicationId,
DateTime.Now);
}
}
}
This takes care of the necessary classes. Next we’ll take a look at the configuration of the on-premise service. This is where the magic happens.
Configuring the WCF REST service
First we’re going to register a few WCF extensions needed to enable relay binding. Run the executable as shown below.

Open app.config and delete the contents of the file. Replace with sample configuration below.
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<webHttpRelayBinding>
<binding name="default">
<!-- Turn off authentication -->
<security relayClientAuthenticationType="None" />
</binding>
</webHttpRelayBinding>
</bindings>
<services>
<service behaviorConfiguration="default" name="DBLOG.BizTalk.ExplorerServices.BtsApplication">
<!-- Register endpoint/service on the Windows Azure service bus -->
<endpoint address="https://molniservices.servicebus.windows.net/BizTalkExplorerServices"
behaviorConfiguration="sharedSecretClientCredentials" binding="webHttpRelayBinding"
bindingConfiguration="default" contract="DBLOG.BizTalk.ExplorerServices.IBtsApplication" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="sharedSecretClientCredentials">
<!-- Register the service as publically avaiable -->
<serviceRegistrySettings discoveryMode="Public"/>
<webHttp/>
<transportClientEndpointBehavior credentialType="SharedSecret">
<clientCredentials>
<sharedSecret issuerName="owner" issuerSecret="" />
</clientCredentials>
</transportClientEndpointBehavior>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="default">
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
For this exercise we’ll turn off authentication against the service by setting relayClientAuthenticationType to None. In the case of needing to authenticate against the service we could retrieve a token using the Access Control Service – but fir this exercise we’re going to keep it simple.
Copy the Default Key which we got from the Management Portal in part one and set the issuerSecret-attribute of the sharedSecret-element to this value.
Registering the service on the AppFabric Service Bus
When you fire up the service it will automatically register itself on the AppFabric Service Bus. Note the serviceRegistrySettings-element with the attribute discoveryMode which is set to Public. This will make the service become listed at https://yournamespace.servicebus.windows.net/.
Testing the service
Since we implement the service with a REST API we can call it directly using the browser by calling the address https://yournamespace.servicebus.windows.net/BizTalkExplorerServices/GetApplicationStatus/1.

That’s it! We can now call our on-premise service from the cloud – awesome!
With that we’re done with part two. Let’s move on to part three where we call the service from EPiServer CMS.