Within the Azure Platform, there is a set of services named .NET Services. These set of services were originally known as BizTalk.NET, and it includes the Workflow Services, the Access Control Services, and the one we will talk about, the Service Bus.
The Service Bus implements the familiar Enterprise Service Bus Pattern. In a nutshell, the service bus allows for service location unawareness between the service and its consumer, along with a set of other, rather important, capabilities. The Service Bus allows you to build composite applications based on services that you really do not need to know where they are. They could be in servers inside your company, or on a server on the other side of the world; the location is irrelevant. There are, nevertheless, important things you need to know about the service you are calling, namely, security. The Access Control Service integrates seamlessly with the Service Bus to provide authentication and authorization. The Access Control Service will be addressed in some other entry, for now we are concentrating on the Service Bus.
The following diagrams depict different scenarios where it makes sense to use the Service Bus.
Depending on the Service Bus location, it can take a slightly different designation. If the Service Bus is installed and working on-premises, it is commonly known as an ESB (Enterprise Service Bus), if it is on the cloud, it takes the designation ISB (Internet Service Bus). It is still not clear what Microsoft´s intentions are regarding an on-premises offering of the Azure Platform. The following diagram shows another possible scenario for using the Service Bus.
As I mentioned before, there are several other benefits associated with the use of the Service Bus that can be leveraged by the configuration shown in this diagram. For instance, the Service Bus also provides protocol mediation allowing use of non-standard bindings inside the enterprise (e.g., NetTcpBinding), and more standard protocols once a request is forwarded to the cloud (e.g., BasicHttpBinding).
Going back to our example, we are going to setup the publisher/subscriber scenario depicted in the following diagram.
Let´s start by building the service. To do so follow the steps:
1) Sign in to the Azure Services Platform Portal at http://portal.ex.azure.microsoft.com/
2) Create a solution in the Azure Services Platform Portal. This solution will create an account issued by the Access Control Service (accesscontrol.windows.net). The Access Control Service creates this account for convenience only, and this is going to be deprecated. The Access Control Service is basically an STS (Security Token Service), there is no intention from Microsoft to build yet another Identity Management System. Although it integrates with Identity Management Systems such as Windows CardSpace, Windows Live Id, Active Directory Federation Services, etc.
3) Create a console application named “ESBServiceConsole”
4) Add a reference to the “System.ServiceModel” assembly
5) Add a reference to the “Microsoft.ServiceBus” assembly. You can find this assembly in the folder “C:\Program Files\Microsoft .NET Services SDK (March 2009 CTP)\Assemblies\Microsoft.ServiceBus.dll”. By the way I am using the March 2009 CTP on this example, you can find it at http://www.microsoft.com/downloads/details.aspx?FamilyID=b44c10e8-425c-417f-af10-3d2839a5a362&displaylang=en
6) Add the following interface to the “program.cs” file
[ServiceContract(Name = “IEchoContract”, Namespace = “http://azure.samples/”)] public interface IEchoContract { [OperationContract(IsOneWay = true)] void Echo(string text); }
|
7) Add the following class to the program “program.cs” file
[ServiceBehavior(Name = “EchoService”, Namespace = “http://azure.samples/”)] class EchoService : IEchoContract { public void Echo(string text) { Console.WriteLine(“Echoing: {0}”, text); } }
|
8) Add the following code to the “main” function
// since we are using a netEventRelayBinding based endpoint we can set the conectivity protocol, in this case we are setting it to http ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
// read the solution credentials to connect to the Service Bus. this type of credentials are going to be deprecated, they just exist for convenience, in a real scenario one should use CardSpace, Certificates, Live Services Id, etc. Console.Write(“Your Solution Name: “); string solutionName = Console.ReadLine(); Console.Write(“Your Solution Password: “); string solutionPassword = Console.ReadLine();
// create the endpoint address in the solution’s namespace Uri address = ServiceBusEnvironment.CreateServiceUri(“sb”, solutionName, “EchoService”);
// create the credentials object for the endpoint TransportClientEndpointBehavior userNamePasswordServiceBusCredential = new TransportClientEndpointBehavior(); userNamePasswordServiceBusCredential.CredentialType = TransportClientCredentialType.UserNamePassword; userNamePasswordServiceBusCredential.Credentials.UserName.UserName = solutionName; userNamePasswordServiceBusCredential.Credentials.UserName.Password = solutionPassword;
// create the service host reading the configuration ServiceHost host = new ServiceHost(typeof(EchoService), address);
// add the Service Bus credentials to all endpoints specified in configuration foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { endpoint.Behaviors.Add(userNamePasswordServiceBusCredential); }
// open the service host.Open();
Console.WriteLine(“Service address: “ + address); Console.WriteLine(“Press [Enter] to exit”); Console.ReadLine();
// close the service host.Close();
|
Notice that I chose the Tcp protocol as the connectivity mode. In the client side, I will specify the Http protocol. This is to show that protocol mediation can be accomplished with the use of the Service Bus.
9) Add an “app.config” file to the project
10) Add the following configuration to the “app.config” file
<system.serviceModel> <services> <service name=“ESBServiceConsole.EchoService“> <endpoint contract=“ESBServiceConsole.IEchoContract“ binding=“netEventRelayBinding“ /> </service> </services> </system.serviceModel>
|
11) Compile and run the service. Enter the solution credentials, and you should get the following:
Now let´s build a client application.
1) Add a console project named “ESBClientConsole” to the solution.
2) Add a reference to the “System.ServiceModel” assembly.
3) Add a reference to the “Microsoft.ServiceBus” assembly.
4) Add the following interface to the “program.cs” file
[ServiceContract(Name = “IEchoContract”, Namespace = “http://azure.samples/”)] public interface IEchoContract { [OperationContract(IsOneWay = true)] void Echo(string text); }
public interface IEchoChannel : IEchoContract, IClientChannel { }
|
5) Add the following code to the “main” function
// since we are using a netEventRelayBinding based endpoint we can set the conectivity protocol, in this case we are setting it to http ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Tcp;
// read the solution credentials to connect to the Service Bus. this type of credentials are going to be deprecated, they just exist for convenience, in a real scenario one should use CardSpace, Certificates, Live Services Id, etc. Console.Write(“Your Solution Name: “); string solutionName = Console.ReadLine(); Console.Write(“Your Solution Password: “); string solutionPassword = Console.ReadLine();
// create the service URI based on the solution name Uri serviceUri = ServiceBusEnvironment.CreateServiceUri(“sb”, solutionName, “EchoService”);
// create the credentials object for the endpoint TransportClientEndpointBehavior userNamePasswordServiceBusCredential = new TransportClientEndpointBehavior(); userNamePasswordServiceBusCredential.CredentialType = TransportClientCredentialType.UserNamePassword; userNamePasswordServiceBusCredential.Credentials.UserName.UserName = solutionName; userNamePasswordServiceBusCredential.Credentials.UserName.Password = solutionPassword;
// create the channel factory loading the configuration ChannelFactory<IEchoChannel> channelFactory = new ChannelFactory<IEchoChannel>(“RelayEndpoint”, new EndpointAddress(serviceUri));
// apply the Service Bus credentials channelFactory.Endpoint.Behaviors.Add(userNamePasswordServiceBusCredential);
// create and open the client channel IEchoChannel channel = channelFactory.CreateChannel(); channel.Open();
Console.WriteLine(“Enter text to echo (or [Enter] to exit):”); string input = Console.ReadLine(); while (input != String.Empty) { try { channel.Echo(input); Console.WriteLine(“Done!”); } catch (Exception e) { Console.WriteLine(“Error: “ + e.Message); } input = Console.ReadLine(); }
channel.Close(); channelFactory.Close();
|
6) Add an “app.config” file to the project
7) Add the following configuration to the “app.config” file
<system.serviceModel> <client> <endpoint name=“RelayEndpoint“ contract=“ESBClientConsole.IEchoContract“ binding=“netEventRelayBinding“/> </client> </system.serviceModel>
|
8) Compile the client, run three instances of the service, enter the credentials, run the client and type some text, the result should be as follows.
There you have it, a publish/subscribe example using the Service Bus.
Excellent, I was looking for an example + discussion like this!
Cheers,
Vincent-Philippe
Hi there! Someone in my Myspace group shared
this site with us so I came to look it over.
I’m definitely enjoying the information. I’m book-marking and will be tweeting this to my followers!
Terrific blog and outstanding design.
Hi there! Someone in my Facebook group shared this
website with us so I came to look it over. I’m definitely enjoying the information. I’m
bookmarking and will be tweeting this to my followers! Exceptional
blog and wonderful style and design.
constantly i used to read smaller articles or reviews
that as well clear their motive, and that is also happening with this post which I am reading now.
Everyone loves it when people get together and share thoughts.
Great blog, keep it up!
This is an awesome site, I will definitely be sure to add your site
to my bookmarks!
Everything is very open with a clear clarification of the issues.
It was really informative. Your website is very useful.
Many thanks for sharing!
Pretty section of content. I just stumbled upon your weblog and in
accession capital to assert that I get in fact enjoyed account your blog posts.
Anyway I’ll be subscribing to your augment and even I achievement you access consistently rapidly.
How are you? I came across this site using web search engines.
I think this info extremely interesting. I’ll make sure to add it to my bookmarks as well as return to find out more. Thank you for the update. I will definitely return.!!!
Good day! Do you use Twitter? I’d like to follow you if that would be ok. I’m absolutely enjoying your blog and look forward
to new updates.
I simply wanted to write down a simple comment in order to thank you for
all of the magnificent recommendations you are showing on this site.
My time consuming internet look up has at the end been paid with good content to exchange with my companions.
I would repeat that many of us readers are truly endowed to dwell in a very good network with many brilliant individuals with helpful hints.
I feel very happy to have come across your website page and look forward to plenty of more fun times reading here.
Thank you once more for everything.
Hi! I’ve been reading your site for a long time now and finally got the bravery to go ahead and give you a shout out from Humble Tx! Just wanted to say keep up the excellent job!
What’s up, just wanted to mention, I enjoyed this article. It was practical. Keep on posting!
Attractive portion of content. I simply stumbled upon your weblog and
in accession capital to say that I acquire actually enjoyed
account your blog posts. Anyway I will be subscribing in
your augment or even I fulfillment you get admission to consistently rapidly.
pretty fantastic snapshots.
Hello There. I discovered your blog the use of msn.
This is a really neatly written article. I’ll be sure to bookmark it and return to read extra of your useful info. Thank you for the post. I’ll definitely return.
If some one desires expert view on the topic of running a blog then i propose him/her to pay a visit this website,
Keep up the pleasant work.
I must show thanks to the writer for bailing me out of this dilemma.
As a result of looking out throughout the search engines and
getting advice which were not beneficial, I believed my life was over.
Being alive without the presence of answers to the difficulties
you’ve resolved through your main article is a crucial case, as well as those which may have badly damaged my entire career if I had not encountered your web blog. That training and kindness in touching all the things was invaluable. I don’t know what I would’ve done if I hadn’t encountered such a subject like this.
I am able to now look forward to my future. Thanks for your time so much for your specialized and effective guide.
I will not hesitate to recommend your blog to anyone who needs counselling on this topic.
I do not even know how I finished up right here, but I
assumed this post was once good. I don’t understand who you might be however certainly you’re
going to a famous blogger if you happen to are not already.
Cheers!
Hi there, I log on to your blogs regularly. Your writing
style is awesome, keep up the good work!
After looking into a few of the articles on your site,
I honestly like your way of blogging. I saved it to my bookmark website list and will be checking back in the near future.
Please visit my website as well and let me
know your opinion.
You made some really good points there. I checked on the net to find out
more about the issue and found most people will go along with your views on
this website.
I absolutely love your blog and find a lot of your
post’s to be just what I’m looking for. can you offer guest writers to write content for yourself?
I wouldn’t mind producing a post or elaborating on some of the subjects you write concerning here. Again, awesome web log!
Everyone loves it when individuals come together and share thoughts.
Great blog, keep it up!
Target Characteristics: These are characteristics that reference the one who receives and operations a message.
Larger organizations tend to have stricter, expressly written rules on etiquette.
In addition, Wikipedia can be extremely helpful at
any time that a student encounters a term, name, and other little bit
of information that’s unfamiliar.
I’m amazed, I must say. Rarely do I come across a blog that’s both educative
and interesting, and let me tell you, you’ve hit the nail on the head.
The problem is an issue that too few people are speaking intelligently about.
I am very happy I came across this in my hunt for something
regarding this.
Excellent way of telling, and pleasant article to get information on the topic of my presentation subject matter, which
i am going to deliver in school.