Windows Azure Service Bus (6) relay (Relay on) uses VS2013 to develop Service bus Relay on

Source: Internet
Author: User

Windows Azure Platform Family of articles Catalog

Note: This article describes a domestic Windows Azure service that is connected by the century.

Please download the project file here.

  When we use the Azure platform, we often encounter interoperability between on-premises and cloud-based applications.

In this hybrid cloud scenario, we can address this in the following ways:

 A. Point-to-site VPN

Connect a local device (point) to the Cloud Network (Site).

-Point here refers to a host in the enterprise Intranet (VPN client)

-Site here refers to the network of azure Virtual networks

-This enables the interconnection of one host in the intranet with the cloud network, while ensuring the security of the network through a VPN

Intranet hosts need to install VPN client

The following client operating systems are supported:

Windows 7 (32-bit and 64-bit)

Windows Server R2 (only 64-bit supported)

Windows 8 (32-bit and 64-bit)

Windows Server 2012 (only 64-bit supported)

Point-to-site VPN is using the SSTP VPN protocol

Interested readers can refer to the author's previous articles:

  Windows Azure Virtual Network (8) creates an azure Point-to-site point-to-site VPN

 Two. Site-to-site VPN

  Connect your local network (site) to the Azure virtual Network (site) in the cloud.

Site-to-site VPN Premise requirements:

-Corporate local network requires a fixed public network IPV4 address

-Requires a Microsoft-certified VPN device or Windows Server. RRAS

For a list of devices, please refer to:https://msdn.microsoft.com/en-us/library/azure/jj156075.aspx

-The VPN device must be in front of the NAT device

  Site-to-site VPN is using IPSec VPN protocol

I'll write this article back:)

As you can see, the Azure Virtual Network VPN approach is based on the TCP/IP network protocol.

In many scenarios, implementing Point-to-site and Site-to-site is not very easy. For example, the following scenario:

-Enterprise does not have a fixed public network IPV4 address

-Enterprise IT policies that do not allow setting up an azure Site-to-site VPN

In this case, you can use Azure Service Bus Relay on to implement the hybrid cloud of the application tier .

Azure Service Bus Relay on

- do not rely on fixed public network IPV4 or VPN devices

-Can penetrate the NAT device

Such as:

  

Azure Service Bus Relay on is a hybrid cloud that implements the application over HTTP, https. If you need to publish the enterprise intranet WCF application services to the public network, by other clients to call the time, only in the enterprise intranet allow HTTP requires 80 port, or HTTPS required 443 port.

In addition, there is no direct call between the WCF Application service on the intranet and the client (extranet) application service. Instead, you first need to register the WCF service in Azure Service bus Relay on, and the client (extranet) app can invoke the registered Azure service bus Relay on. Azure Service Relay on is conceptually similar to a proxy server.

  

  Note: Azure Service bus applications currently only support WCF services in the enterprise intranet.

The previous introduction is over, now into the demo stage. The author simulates the following scenarios:

1. In the enterprise intranet, there is a Web service with a WCF service deployed above

2. Register WCF on the service bus via Azure Service bus Relay on.

3. From another client machine on the Internet, invoke the service on the Azure service bus Relay on by verifying the SAS authentication of the service bus .

The following items fall into three categories:

-Create Azure Service Bus Relay on using PowerShell

-On the server side, register the WCF service to Azure service Bus. Because the WCF project executes, the host is required, and the project is hosted on Windows console.

-Clients, machines on the Internet, call the Azure Service bus registered WCF services

I. Using PowerShell to create an azure Service Bus Relay on

readers should note that Azure Service Bus Relay on can only be created through PowerShell. How the reader has created Azure service through management Portal does not normally use the relay on feature. Need to be deleted and rebuilt via PowerShell.

1. We run Azure PowerShell with administrator status

2. If the reader has multiple azure subscriptions, switch the current subscription

' [Yoursubscriptionname] ' -current

3. Execute the following code:

' [Yourservicebusname] ' ' Messaging ' ' [Yourlocation] '

For example, the service bus name I want to create is called Leiservicebus and is located in the China East Data Center

' Leizhangservicebus ' ' Messaging ' ' China East '

The following are the results of the execution:

4. You can see the creation results in Azure Management portal. We can also view the connection string for service bus, such as:

  

 Note: Whether the client can connect to Azure Service Bus relay is verified by the connection string above.

Above, the work of creating Azure Service Bus Relay on is complete.

 Two. Server-side, registering a WCF service with the Azure services Bus

  Next, we run Visual Studio 2013 with administrator status. Create a new project with the duplicate name Sbrelay.

1. Add the Windows Console Library, named Sbrelayserver

2. Add the following code to Program.cs:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.ServiceModel;usingFoundation;usingMicrosoft.servicebus;usingSystem.ServiceModel.Description;namespacesbrelayserver{classProgram {Static voidMain (string[] args) {            varTokenprovider = Tokenprovider.createsharedaccesssignaturetokenprovider ("Rootmanagesharedaccesskey","+lsd5njwikuzei+ry/npkkr/gl3plpvrgcv23gwkrm0="); varServiceHost =NewServiceHost (typeof(EchoService)); varServiceEndpoint =Servicehost.addserviceendpoint (typeof(Iecho),Newnettcprelaybinding (),"Sb://leizhangservicebus.servicebus.chinacloudapi.cn/echo"); SERVICEENDPOINT.BEHAVIORS.ADD (NewTransportclientendpointbehavior (Tokenprovider));            Servicehost.open (); Console.WriteLine ("Press ENTER to close");            Console.ReadLine ();        Servicehost.close (); }    }}

  Note: The Tokenprovider is our SAS key.

In the above application, the local WCF is registered to Azure Service Bus in the cloud with the address Sb://leizhangservicebus.servicebus.chinacloudapi.cn/echo

3. In the Sbrelayserver project, add EchoService.cs and enter the following code:

usingFoundation;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacesbrelayserver{classEchoservice:iecho { Public stringGetValue () {return "Hello world!"; }    }}

The server side is returned to the client string with the content Hello world!

Three. Client, calling from client

1. Add the Windows Console Library, named Sbrelayclient

2. In Program.cs, add the following code:

usingMicrosoft.servicebus;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.ServiceModel;usingSystem.Text;usingSystem.Threading.Tasks;usingFoundation;usingSystem.Diagnostics;namespacesbrelayclient{classProgram {Static voidMain (string[] args) {            varbinding =Newnettcprelaybinding (); varChannelFactory =NewChannelfactory<iechochannel>(binding,NewEndpointAddress ("Sb://leizhangservicebus.servicebus.chinacloudapi.cn/echo")           ); CHANNELFACTORY.ENDPOINT.ENDPOINTBEHAVIORS.ADD (NewTransportclientendpointbehavior {tokenprovider = Tokenprovider.createsharedaccesssignaturetokenprovider ("Rootmanagesharedaccesskey","+lsd5njwikuzei+ry/npkkr/gl3plpvrgcv23gwkrm0=") }); using(varCH =Channelfactory.createchannel ()) {Stopwatch SW=NewStopwatch (); Sw.                Start (); stringReturnValue =Ch.                GetValue (); Sw.                Stop (); Console.WriteLine ("Get {0} from WCF Server", returnvalue);        } console.readline (); }    }}

In the above code, the GetValue method is read from the server and returned to the client string.

 How do I execute the code?

1. Compiling the project file

2. Execute the server-side project, sbrelayserver the SBRelayServer.exe under the project.

3. Wait until the server-side project, SBRelayServer.exe command line displays press ENTER to close, do not close SBRelayServer.exe

4. Execute the client project, sbrelayclient the SBRelayClient.exe under the project

5. The left side is the server-side command-line interface, and the right side is the client command-line result, where Hello World is the server's return value.

Bo-Three Stone Blog (hereinafter referred to as Benbow), at the end of this blog article at the bottom of the right is not noted reproduced, source, provenance of the works (content) are the original, the site for the original content of the copyright reserved, do not arbitrarily reproduced, if the need for a friend can send mail contact me; reproduced original works (content ) must also follow the Creative Commons agreement "attribution-non-commercial use-consistent", be sure to indicate or retain the original source of the article and the information of the blogger (Lei Zhang) in the form of a text link, and be sure to keep in mind that the photograph works on this blog (www.cnblog.com/ Threestone) and other relevant watermark copyright information, otherwise deemed to infringe the original Copyright Act; Benbow declined commercial website reprint. All rights reserved, prohibit illegal and malicious plagiarism which violates the copyright protection Law of the People's Republic of China and related laws and Benbow (legal) statement.

Windows Azure Service Bus (6) relay (Relay on) uses VS2013 to develop Service bus Relay on

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.