8. Peeking under the hood AppFabric & Related Features Microsoft Confidential Persistence Monitoring Hosting Caching Messaging IIS 7.x/WAS IIS Manager .NET 4 WCF & WF Frameworks SQL Persistence Provider WF & WCF Management Modules Runtime Databases Persistence schema Monitoring schema WF ETW Tracking WCF ETW Tracking Web Deploy Visual Studio Windows 7, Windows Server 2008 & 2008 R2 Service Discovery Reliablility, Scalablity Availability, Deployment, Control Application Monitoring Instance Restart AutoStart Service Workflow Mgmt Event Collector Server Manager AppFabric Role Service of Application Server Role System Center Management Pack In Memory, Distributed Cache Routing Service Activation Project Deployment WF & WCF Project Templates Mgmt PowerShell cmdlets Configuration Wizard Lock Mgmt
18. Introducing Fourth Coffee Order Fulfillment Service ASP.NET Form Silverlight Application WCF WFS WFS ASMX WFS Workflow Service WCF SOAP Service ASMX Web Service WCF ASMX WFS Submit Order Create Label Approve Label Reserve Inventory Check Credit Finalize Order Order State Inventory Labeling Client Web App Credit Card Processing
Services Architecture Introduce Windows Server AppFabric Introduce the Fourth Coffee scenario Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
Services provide and encapsulate the functionality for a wide variety of clients. As you can see in the diagram, the clients of a service can be Front-End Clients such as those hosted in the Web Browser either as Rich Internet Applications built with Silverlight or HTML with AJAX- often times these require direct access to the services. They can also be “thick” clients such as WPF or WinForms that run on the desktop. Finally, Mobile clients are providing richer experiences and with services can tap into a wealth of data and functionality on the go. ASP.NET Pages, while rendered in the browser, actually make their service calls within the IIS hosting process, and thus present one time of Middle Tier client of services. By their nature, services are designed to be composable so that one service can call another, and often times the Middle Tier includes services which compose multiple services as a unit to expose higher level functionality. Regardless of if a service is invoked directly from a Front-End client or a Middle Tier client, in the .NET Framework these services are built using WCF. WCF Services can be categorized into three categories called service models based on the type of functionality they expose. An Entity Service model exposes functionality to work with business entities such as customers. A Task service model serves to coordinate a process, such as that followed during Invoice Approval. Finally, a utility service provides for computation not directly related to entities, such as a service that provides sales tax calculation. As will be shown, there are many different ways to implement services with WCF. We provide guidance based on these three service models to help you in narrowing your choices.
In this class we will be focusing on two forms of implementing WCF Services to empower your clients. As you will see, each has distinct advantages that make selecting one approach more compelling than the other, but in the end you are always building WCF Services. WCF SOAP Services are service you write in code. Because they are quick to build and expose functionality they are shine with building both Entity and Utility service model style services. They can be used for implementing service in the Task model, but because they do not have intrinsic support for long running processes, more implementation code is required. WCF Workflow Services are services defined visually and have intrinsic support for efficiently handling long running processes. Because of this support, you’ll likely choose WCF Workflow Services for implementing your Task services which coordinate steps in larger process. Their visual definition enhances the ability to understand and communicate what a long running processes does to other stakeholders in the project, without having to read through code. That said, Workflow Services can certainly be used to perform CRUD operation on entity data or exposes utility functions. In the end, there is no hard and fast rule of when to choose one implementation approach over the other, but knowing if you will be bulding Task services versus Entity/Utility services should make you consider WCF Workflow Services first. Finally, realize that these services are composable, so you can use both WCF SOAP Services and WCF Workflow Service in your complete solution, one calling the other as needed.
Earlier in the class you may have learned how AppFabric helps with caching. In this class we show how AppFabric helps you host WCF Soap Services and Workflows Services in IIS and WAS. You can think of Window Server AppFabric as both an extension and a platform. It is a platform because it provides new infrastructure that assist with hosting WCF SOAP and Workflow services. This platform leverages the Windows Process Activation Service (WAS) for launching instances of these services across different protocols (HTTP, MSQM, TCP/IP, Named Pipes, etc). It provides for collecting diagnostic events, storing the state of long running service instances, and managing those instances for reliability. It is an extension because it tacks in new user interfaces to IIS Manager that help you monitor, manage and configure both WCF SOAP and Workflow Services. Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
So what features does AppFabric provide? Within IIS Manager, it provides a Dashboard within which you can monitor the status of your services. The dashboard can roll up its service stats data from individual applications, a web site or even provide a top level overview of all services running on the server. <NEXT> From the dashboard, you can drill down into more detailed tracked events to review both the normal operation and failure cases. You can even customize the query used to return the tracked events in an intuitive manner. <NEXT> Beyond helping you monitor your services, the interfaces AppFabric provides assist with configuration and minimize the time you spend editing XML config files. Take this case where we can easily turn up the volume on the tracked events. <NEXT> And there’s a lot more functionality under the hood that AppFabric provides, enhances or simply leverages…. Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
AppFabric enhances, utilizes and provides a lot of functionality. It’s important to take away that in building your complete solution, you will combine a lot of features provided by Windows, .NET 4, Web Deploy, Visual Studio, IIS | WAS, IIS Manager and PowerShell with features from Windows Server AppFabric. A WCF services solution built to run with AppFabric must run on Windows 7, Server 2008 or 2008 R2. It will inherently leverage features from IIS 7/7.5 and WAS as well as .NET 4. You will build these solutions using Visual Studio 2010 and manage them using IIS Manager or with PowerShell cmdlets. In this class, we will focus on features pertaining to Hosting, Persistence, Monitoring and Messaging. When it comes to Hosting, AppFabric provides functionality that improve the availability of your solution both by optimizing service responsiveness with Auto Start and by a Windows service that ensures that your Service Hosts are running when they should be. Deployment is a natural part of developing service solutions, so Web Deploy is an integral part of an AppFabric solution when moving from development to test, test to prod or even between prod nodes. Persistence is the cornerstone of what AppFabric provides that supports the efficient execution of long-running workflow services. These services will execute within IIS and WAS, but when they go idle, they are written to a SQL Server database and unloaded from memory until needed again. Because multiple hosts can be used to run services persisted in the SQL store AppFabric provides functionality to resume workflow instances from service hosts that have failed, as well as gracefully handling the contention that may occur when multiple service hosts attempt to load the same service instance from the database. AppFabric provides for robust monitoring of your application, allowing you to collect events from both WCF SOAP and Workflow Services in a highly performant and resource efficient manner using ETW. AppFabric provides a SQL Databases in which to store these events, which simplifies building custom reports and dashboards. These events can track low level details such as the service operation executed, to higher level items such as the values of business data being modified within a workflow service. Finally, AppFabric builds upon Messaging features that activate your WCF SOAP Services or WCF Workflow services in response to incoming messages. Your AppFabric solutions can leverage the WCF Routing Service to provide message content based routing and assist with the versioning of your services.
AppFabric hosting features solves some problems that you may have encountered in building your own services previously. As we go through the modules you will see how AppFabric helps you improve startup performance for first message received by a service as well as the many ways it improves the reliability of long running service instances.
Your server is more scalable because you have AppFabric. It’s scalable because you can deploy AppFabric in a farm and scale out. You can leverage custom routing to load balance service requests. Your services can kick off long computations asynchronously, and wait for the result without being loaded in memory. Because they are stored centrally, your workflow services are server and process agnostic, allowing them to execute on the host that’s available.
Windows Server AppFabric comes at no additional cost- your license of Windows Server 2008 includes a production license. There are some caveats to be aware of when planning your infrastructure deployments. AppFabric will run on Windows 7, Windows Vista with SP2 and Windows Server 2008 or R2 in a workgroup mode, but the license only allows this for development. If you want to run Windows Server AppFabric in production, you must run it on Windows Server 2008 or R2 that is joined to a domain. For those of you who have built workflow service in .NET 3.5, you can still host these with AppFabric, but understand you will miss out on the vast majority of the features which specifically target .NET WCF SOAP and Workflow Services. Similar to IIS/WAS, Windows Server AppFabric will become a part of the operating system, but for now it is available as separate installation.
AppFabric is installable from the Web Platform installer- a download available from Microsoft.com/web. The Enterprise tab on which AppFabric appears is not visible by default. You need to click the options link at the bottom left corner of the screen and in the dialog that appears check enterprise and click OK. You should use the Web Platform Installer approach when installing your development environment. It will automatically setup the complete caching and hosting features. For the setup of production environments, you should still use the MSI, as it is not recommended to install Caching and Hosting features on the same production server. Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
When you are running the installation from the setup redistributable, you have the option to choose which features will be installed. In general you would not install the AppFabric Hosting and Caching Services features on the same server. In this class we will be focusing only on the functionality provided by the Hosting Services and Hosting Administration features. Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
A key aspect of hosting is configuring the storage location for the persisted workflow service instances as well as for all the monitoring events collected. After the main installation completes, the installer by default will launch the Windows Server AppFabric Configuration Wizard. If you are going to be using SQL Server for both persistence and monitoring, this Wizard makes it easy to create the monitoring database, tracking database as well as configure the service accounts that interact with each. You can re-run this wizard any time outside of setup, it’s on the Start Menu under the Windows Server AppFabric program group. As you can see in the screenshot, the Wizard is smart enough to detect if you have previously configured these stores. Let’s take a look at what it takes to configure the monitoring store to use SQL Server, and then we will return to configuring persistence. From the Monitoring provider, you select the SqlClient option which enables the Configure… button. The monitoring provider is pluggable, AppFabric allows you to use non-SQL stores and the Wizard is extensible show the appropriate configuration dialog for such custom providers. Clicking the Configure… button with the SqlClient selected takes us to the following SQL Server specific dialog. Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
Here we effectively define the connection string AppFabric will use to connect to the monitoring database, by specifying the Server and Database name, as well as the credentials AppFabric will use to login to the database. In a domain joined scenario, you will want to specify domain groups in the Administrators, Readers, Writers fields. These will map to database roles in the monitoring database. In a workgroup, you could use SQL Server authentication, but be CAREFUL! The sql password is written in root web.config unencrypted- it’s up to you to later encrypt it within a protected section. If you are just installing AppFabric on your development box, then you can usually leave the roles to the local accounts created during installation. Now that you have a connection string, we can turn our attention to the first two checkboxes. The topmost one, Register AppFabric monitoring store in root web.config when checked will add a connection string element as configured to the web.config under the windows\\system32\\microsoft.net\\framework\\v4.x\\config folder. This will make it available to all sites and applications on the server and is typically what you want. The second box, Initialize monitoring store, when checked will actually create the database and all schema objects in the database pointed to by the connection string defined. In a farm scenario, only the first server in the farm needs to initialize the monitoring store as the rest will simply have a connection string point to it. Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
The configuration of the SQL persistence store works in exactly the same fashion. It is recommended as a best practice that you create a separate database for the monitoring and persistence stores. Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
So let’s dive into a demo of our scenario that makes use of Windows Server AppFabric to host a solution for ordering coffee beans. Placing an order from the Fourth Coffe ASP.NET website Approve the proof via Silverlight and fulfilling it within Fourth Coffee. Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
As you saw in the demo, the client of the Fourth Coffee solution is an ASP.NET website. The client fills out a form and submits in order. <CLICK> What you didn’t see is what goes on behind the scenes. Let’s look at the now. <CLICK> The order is received by the SubmitOrder operation defined in a Workflow Service called the Order Fulfillment Service. <CLICK> The implementation of this operation makes a call out to a WCF SOAP Service called OrderState that is responsible for tracking the status of orders. <CLICK> Next, the workflow will attempt to verify that there is sufficient stock in inventory to satisfy the order, and if so reserve it. <CLICK> To do this it makes a call out to the Inventor Service, which is a WCF Workflow Service that defines the logic for interacting with the inventory database. <CLICK> Assuming the reservation was successful, the label submitted by the customer is generated. <CLICK> This is done by calling out to the Labeling Service which contains the image processing logic for merging the customer submitted image with the Fourth Coffee text. <CLICK> When the label is ready, the customer is able to preview it in a Silverlight application. The Order Fulfillment Service will wait for the customer to approve the label before continuing. <CLICK> The customer’s approval in the Silverlight application is received by the ApproveLabel operation . <CLICK> Next, the customer is billed for the order. <CLICK> This is accomplished by calling out to a legacy ASMX web service. <CLICK> Assuming the charge is successful, the order is finalized. <CLICK> The order fulfillment service coordinates the cleanup of the temporary files created for the order via another call to the labeling service. In the case that the charge was not succesful, it also coordinates a call back to the inventory service to unreserve the items. Recall from the introduction on service architecture our service model types. Here you can see how the Order Fulfillment Service is a task service that is simply coordinating calls between other services. The OrderState and Inventory services exemplify Entity services as they are used manage Order and Inventory entities respectively. The Labeling and Credit Card Processing services are Utility services because they provide specific functionality not particular to any business entity. Service MODEL types Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential
Windows 7 | Presenter Mode Monday, October 31, 2011 Microsoft Confidential