Azure service bus relay
Everything at the moment seems to be pointing to cloud services like Azures. Why not as the services like Azure are powerful and give you more power to work with.
There are some issue, you need to consider and conker. For example if you need to access services or data on an internal server and you do not want to alter any firewall or access.
This is where The Service bus from Azure come into play. All you need to do is set up the Azure service for the Bus on Azure. Then create a simple service or console app, which site on your network that can access the azure site.

This will take you through how to make a simple Relay bus with to communicate with Azure.

The project
When you create a Console or service project, you need to make sure you install the Microsoft Azure Service Bus. This is a NuGet package.
Once you've installed the package you will need to go into your App.Config file and make sure you have the correct AppSettings key setup "Microsoft.ServiceBus.ConnectionString".
This is the end point element and you will need to use the Service bus elements, you have from the Azure Service setup on the Azure Server side.

KEY: Microsoft.ServiceBus.ConnectionString
VALUE: "Endpoint=sb://[APPLICATIONNAME].servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=[ACCESSKEY]"


Interface class
This is a simple interface class, which shows your Azure service/application methods and data classes it can consume

namespace AzureWSSimple
{
[DataContract]
public class SimpleDataClass
{
[DataMember]
public Guid Id{ get; set; }
[DataMember]
public string StringKey { get; set; }
[DataMember]
public string StringValue { get; set; }

}

[ServiceContract]
public interface ISimple
{
[OperationContract]
List<SimpleDataClass> SimpleMethod(Guid Id);

}

interface ISimpleChannel : ISimple, IClientChannel
{
}
}


Logic class
This simple code is the class which the interface referrer too


namespace AzureWSSimple
{
public class SimpleLogic : ISimple
{


public List<SimpleDataClass> SimpleMethod(Guid Id)
{
List dataElement = new List();

return dataElement;

}
}


Running the Logic
The next element is creating the logic so the Service run the logic as a Windows Service

Windows Service
If you have not got a Windows Service project setup already, you will need to create a new project and add the Interface and logic class to your new project.

New Project
Within the New Project Search for "Windows Service" and select the project type from the search results.
This creates a program class that contains a main method that load the Service base to the default Service1 class and the runs the ServicesBase object.
I would rename the Service1 Class to something that makes more sense. (SimpleService)
Then Install the NuGet packages for the Azure Service Bus and then create the interface and logic classes into the project.
Make sure your alter you App.Config setting as stated above.

Linking logic to Service
Now that you have service project created you link the logic code using the ServiceHost object as below.
 
namespace AzureWSSimple
{
public partial class SimpleService
{
private ServiceHost sh;
public SimpleService()
{

this.ServiceName = "Azure Simple Service ";
InitializeComponent();

sh = new ServiceHost(typeof(SimpleLogic));

}

protected override void OnStart(string[] args)
{
sh.Open();
}

protected override void OnStop()
{
if(sh !=null)
{
sh.Close();
}
}
}
}


Installing the services
Now that you have created your Windows Service and you need to install the services onto a Windows PC.

Installer within Service
You need to make sure your have a installer class within your project and this is done by following the simple steps
1 - Right click on the SimpleService.cs file and click on View Designer
2 - Right Click anywhere within the design view (black screen) and click Add Installer. This create a class called ProjectInstaller. Within the Design view, you should have a serviceInstaller1
3 - Go to the properties if serviceInstaller1 and make sure the ServiceName matches you service (SimpleService). Always good to add a description

Installer the Service
First thing you need to do is create a release and put the bin content on the PC you require the service to run and then using the installutil, you install your service.
1 - Open Console with Admin rights,
2 - Find the installutil from the .Net folder on the PC (C:\Windows\Microsoft.NET\Framework\[LATEST VERSION]\InstallUtil.exe)
3 - Once found you run the installutil against your new exe service C:\Windows\Microsoft.NET\Framework\[LATEST VERSION]\InstallUtil.exe SimpleService.exe . This then should install the service.
(If you need more info google or check the linked resource "Walk through")
Created: 12/04/2017 Total Comment: 0

Comments

(Not Displayed)
Human validation
Enter 9377 number, before submitting to confirm your human
[Home] [All Blogs] [Contact] [Me]