1. Trang chủ
  2. » Công Nghệ Thông Tin

Introducing Windows Azure- P29 pot

5 192 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

C H A P T E R 4 ■ ■ ■ 113 Windows Azure Application Integration Using WCF Whenever a new technology is introduced to the computing world, it raises a lot of questions for an enterprise or organization regarding integration. How do you integrate an application built on new technology into the existing system infrastructure? What are appropriate tools to select for integration? How do you select the right candidate subsystem to migrate, refactor, or re-engineer? Although Windows Azure provides a revolutionary new platform, it is almost impossible for any organization to migrate the entire existing on-premises system and infrastructure into the cloud platform. Therefore, integration strategies are extremely important. Even subsystems, which are built with Windows Azure technology, still need to be integrated together. Microsoft has already provided cloud-computing-based services, such as .NET Services, SQL Azure, and Live Services. These services provide organizations with rich functionality and a broad range of building blocks for integration. Windows Azure offers amazing, innovative, and attractive features. One of these features is the ability to host an application in the cloud. Not only cloud-based applications, but also the on-premises applications can leverage cloud services and applications. As I mentioned, to run an application from the cloud is far from the whole story. There is always an integration issue associated with the system architecture design. It should not be too difficult to understand why integration plays the essential role. All applications, services, and infrastructures involved in a computing system need to be coordinated in data exchange, resource sharing, status persisting, logic synchronizing, and so on. All these tasks should be done via integration. No matter what integration strategy an organization plans to use, an essential feature of an integration platform is that it must support cross-platform communication. Microsoft BizTalk server and WCF (Windows Communication Foundation, part of .NET 3.0 or later versions of the .NET platform) should meet these criteria. In principle, Microsoft BizTalk server is designed to support any existing communication protocol in the computing world through built-in, third-party, or custom adapters. The great advantages we can take from Microsoft BizTalk server are its power to integrate and call any existing .NET components, to extend a solution with custom pipelines, data mapping functions, and dynamic data transforming and mapping. And it has sophisticated workflow control, business rules integration, and error handling via Windows BizTalk orchestrations. In contrast, the advantage we can get from WCF is that it is a web-services-based platform. WCF is built in to .NET 3.0 and later versions and can be deployed and hosted from Windows Azure. The scope of this book is limited to covering the topic of integrating Windows Azure applications with each other or with other non-cloud-based on- premises applications using Windows WCF. CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 114 Using WCF WCF unifies all the communication models supported by web services, including message queues, .NET Remoting and distributed transactions into a general service-oriented architecture (SOA), and it also supports SOAP (with an optimized SOAP binary format). WCF also supports both JSON and REST data formats. You can flexibly consume data from Windows Azure using Ajax or .NET by simply providing URLs of the target resources. When a method is invoked against specific URLs, parameters from the URLs are automatically extracted and passed into the target method. These features as described make WCF a great integration tool not only for on-premises applications but also for Windows Azure cloud applications, in addition to Windows BizTalk server. WCF services can be hosted from Windows API applications or from IIS. It would make WCF more attractive from the perspective of integration if WCF services could be hosted from Windows Azure. Microsoft .NET Services, originally called BizTalk Services, was designed as a set of highly scalable developer-oriented services hosted in Microsoft data centers as part of the Windows Azure platform. These services are common building blocks or infrastructure services for cloud-based applications. As one of the core services offered by .NET Services, .NET Workflow Services allows you to define highly scalable cloud-based workflows using Workflow Foundation (WF). In addition, the .NET Workflow Service also provides management tools and web-service-based APIs for .NET Workflow Services type and instance management. Moving forward,.NET Workflow Services tightly collaborates with WCF. In this chapter, we are going to explore the fundamental steps of using WCF and WF as a cloud-based application integration platform. Host WCF Service from Azure In this exercise, we are going to build an example to host a WCF service from Windows Azure. Following are the steps we need to perform to reach this goal. 1. From Visual Studio, create a new cloud service web role service project called HostWCFService as shown in Figure 4-1. Figure 4-1. Create a cloud web role service, HostWCFService, from Visual Studio 2. Create a DLL library project called AzureForDotNetDeveloperWCFServiceLibrary. In this project we define a WCF service contract interface, IUserRegisterService, and a data contract class, User, as Listing 4-1 shows. The service contract interface, IUserRegisterService, has two operation contracts defined. AddUser() (taking an instance of User as a parameter) is used to provide a service to add a user when a user registers to a cloud application. GetUserList() is used to retrieve the collection of users who have registered to a cloud application. CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 115 Listing 4-1. WCF Service Contract IUserRegisterService and Data Contract User Definition using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; using System.ServiceModel; namespace AzureForDotNetDeveloperWCFServiceLibrary { [ServiceContract] public interface IUserRegisterService { [OperationContract] void AddUser(User user); [OperationContract] List<User> GetUserList(); } [DataContract] public class User { [DataMember] public string FirstName; [DataMember] public string LastName; [DataMember] public DateTime TimeRegistered; [DataMember] public string Password; } } 3. From the HostWCFService WebRole project in the Solution Explorer panel, right- click on the project node and select Add ➤ New Item to bring up the Add New Item dialog box. Select WCF Service from the dialog window and name it UserRegisterService.svc as Figure 4-2 shows. Add the reference to AzureForDotNetDeveloperWCFServiceLibrary we have just created. There are three changes we need to make after the service component has been inserted into the project: • Open UserRegisterService.svc from Visual Studio by double-clicking on that file node and correct the string value for Service. The string in quotation marks should be the fully qualified class name with namespace: AzureForDotNetDeveloperWCFServiceLibrary.UserRegisterService CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 116 • Delete UserRegisterService.svc.cs from the project because we have already defined the services contracts from AzureForDotNetDeveloperWCFServiceLibrary. • Remove the following section from UserRegisterService.svc by double- clicking on that file node from the Solution Explorer panel of Visual Studio. The results are shown in Listing 4-2: <Code behind="HostWCFService WebRole.UserRegisterService.svc.cs" Figure 4-2. Insert a WCF service item into the HostWCFService WebRole project Listing 4-2. Modify the File UserRegisterService.svc to Use the Correct Namespace and Remove the Code-behind Section <%@ ServiceHost Language="C#" Debug="true" Service="AzureForDotNetDeveloperWCFServiceLibrary.UserRegisterService" %> 4. From Visual Studio, select Tools ➤ WCF Configuration Editor and open the Web.config file of the HostWCFService project as shown in Figure 4-3. Use this tool to configure the WCF service endpoint and metadata endpoint. The results for Web.config are shown in Listing 4-3. The Web.config file can be edited by using any XML editor instead of using WCF Configuration Editor. However I recommend that you edit the WCF configuration file with the configuration editor. This is tedious work, and it is very easy to make mistakes. CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 117 Figure 4-3. Launch WCF Configuration Editor from Visual Studio Listing 4-3. Configuration for WCF Service UserRegisterService.svc <?xml version="1.0"?> <configuration> <appSettings> <add key="AccountName" value="devstoreaccount1"/> <add key="AccountSharedKey" value="<KEY>"/> <add key="BlobStorageEndpoint" value="http://127.0.0.1:10000"/> <add key="QueueStorageEndpoint" value="http://127.0.0.1:10001"/> <add key="TableStorageEndpoint" value="http://127.0.0.1:10002/"/> </appSettings> <connectionStrings/> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules> <remove name="ScriptModule" /> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </modules> <handlers> . for on-premises applications but also for Windows Azure cloud applications, in addition to Windows BizTalk server. WCF services can be hosted from Windows API applications or from IIS. It would. applications with each other or with other non-cloud-based on- premises applications using Windows WCF. CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 114 Using WCF WCF unifies all. later versions and can be deployed and hosted from Windows Azure. The scope of this book is limited to covering the topic of integrating Windows Azure applications with each other or with other

Ngày đăng: 05/07/2014, 01:20

Xem thêm: Introducing Windows Azure- P29 pot