Chapter 4
Silverlight and Service-Oriented Architecture

Chapters 3 and 4 of this book are dedicated to new enterprise architecture concepts. These concepts provide new challenges to enterprises that want to accommodate Enterprise 2.0 and enable development and deployment of Web 2.0–based RIAs.

Chapter 3 discussed the definition of an Enterprise 2.0–ready technology platform and how Silverlight fits that definition. The chapter also defined the possible enterprise-level architecture of the My Album Silverlight RIA, which was originally developed in Chapter 2.

This chapter will mainly focus on defining the service-oriented architecture (SOA) concept in detail. We will make a deep dive into the seven key principles of the SOA concept to deploy Silverlight-based RIAs as software as a service (SaaS). The chapter will end by looking at Silverlight's capability to integrate with Web Services and Language-Integrated Query (LINQ). We will develop a service-oriented sample Silverlight application demonstrating dynamic user interface (UI) creation and dynamic content population using enterprise features such as externalization, LINQ, Web Services, and custom user controls.

Defining Service-Oriented Architecture

No single definition can explain or define the SOA concept. The basic definition of SOA is as follows:1

Service-oriented architecture (SOA) is a method for systems development and integration where functionality is grouped around business processes and packaged as interoperable services.

SOA supports the Enterprise 2.0 concept by aligning three organizational strategic components— product roadmap, technology roadmap, and IT governance model—by enabling implementation of loosely coupled RIAs and deploying them as SaaS. Thus SOA helps organizations migrate from building monolithic, heavyweight, traditional software applications to building distributed, collaborative, loosely coupled SaaS. This explanation leads us to a detailed definition of SOA:

SOA is an architectural concept on how to implement loosely coupled, distributed and lightweight shared services that can be consumed by internal and external applications for systems integration and executing different business processes.

Key Objectives of SOA-Based Applications

Organizations can achieve three basic objectives by developing SOA-based applications:

1. Meet expectations: Understanding users' needs and market expectations is essential for the implementation of successful SOA-based systems. This basic concept ultimately drives organizations to define a business values–driven organizational IT model and develop an integrated IT and product roadmap.

2. Keep it simple: It is important to keep the organization's IT model simple, flexible, lightweight, and sustainable. This basic goal will help to identify key technologies that can enable simplified, lightweight SOA-based systems. The "keep it simple" principle will help IT departments transform from maintenance organizations (i.e., a cost center) to business-enabled organizations (i.e., a profit-making center).

3. Follow the rules: To remain competitive and successful in the digital, diversified global market and achieve maximum user satisfaction, it is critical to provide a secured environment to end users and to consider and comply with government and regulatory body rules, standards, and policies. The proper implementation and monitoring of the organizational-level IT governance model to implement secured and high-performing SOA-based systems is one of the key strategic components of the organization model.

Before getting a technical overview of the SOA concept, I think it is important to understand how SOA-based application objectives can help organizations to achieve their strategic goals in terms of implementing the defined product, technology roadmaps, and effective IT governance.

Figure 4-1 demonstrates the relationship between the three basic objectives of an SOA-based application and the three key strategic components of organizations.

Image

Figure 4.1    SOA concept: relationship between SOA-based application objectives and organizational strategic components

Now let's take a brief look at the three strategic components of organizations.

The product roadmap usually provides a path (mostly with a phased approach) to achieve the stakeholders' short-to long-term business goals in the form of a series of product releases that is very much aligned with the overall organization vision. The product roadmap clearly defines milestones of product releases with a high-level definition of the scope of each release that drives organizations to achieve the "meet expectations" and "keep it simple" basic objectives.

The technology roadmap usually provides strategic technical directions to the organization on the usage of different technology platforms and technology components. The technology roadmap is usually aligned with the organization vision and key vendors' technology roadmap (e.g., if Microsoft Office is one the key technology platforms, the organization technology roadmap should be aligned with the Microsoft Office roadmap). The technology roadmap facilitates directions on the usage of the technology components that drive organizations to achieve the "meet expectations," "keep it simple," and "follow the rules" basic objectives.

As organizations become more and more dependent on IT systems and the markets become more globalized, virtual, and digital, governments place a more controlled, measurable, and governed environment (including IT-related efforts) around organizations. This environment introduces more accountability, performs adequate risk assessment, and facilitates a well-secured and standard organization environment. The IT governance model within the organization is the answer for achieving the mentioned objectives. IT governance is defined as the following:2

Information Technology Governance, IT Governance, or ICT (Information & Communications Technology) Governance is a subset discipline of Corporate Governance focused on information technology (IT) systems and their performance and risk management.

Table 4-1 summarizes the SOA-driven organizations key components—product roadmap, technology roadmap, and IT governance—in terms of "what," "why," "how," and "when" factors that can support the implementation of loosely coupled business process integration services flexible to accommodate changing requirements and policies in the agile mode.

Table 4.1    SOA-Driven Organizations Key Components Matrix

Product Roadmap Technology Roadmap IT Governance
What
  • Understand user needs and market and stake-holders' expectations to identify core business values.

  • Define measurable key deliverables and milestones for each product.

  • Validate deliverables to achieve the "meet expectations" objective.

  • Define short-term and long-term technology platform, technology components, and services.

  • Define migration path to transform legacy systems to Web 2.0–based service-oriented RIAs.

  • Identify high-level loosely coupled, shared, and generic application services aligning with the product roadmap.

  • Identify and document requirements to comply with regulations and policies defined by government and regulatory bodies.

  • Define organization-level security and performance management model. Validate defined IT governance model against the "follow the rules" objective.

Why
  • Justify defined items scope in terms of the business values.

  • Perform different types of analysis for each milestone to predict short-term and long-term return of investment (ROI).

  • Justify identified technology platform, technology components, and applicatin services.

  • Perform different types of technical analysis to predict the short-term and long-term ROI.

  • Validate the technology roadmap and product roadmap to achieve the strategic mission of moving from cost center to profit-making center.

  • Define and document benefits of the implementation of the IT governance model including the security model and performance model.

  • Identify and measure the success factor of implementation of the IT governance model to emphasize the importance of implementing the model.

How
  • Define interdependencies and integration points among business processes.

  • Identify unique behavioral patterns. Identify a shared and reusable list of simplified, distributed, secured, reusable, and loosely coupled product services.

  • Validate identified product services against the "keep it simple" objective.

  • Identify application service needs to be developed, the high-level IT governance model to implement proper security for user management and information exchange, and the infrastructure environment by defining the high-level enterprise architecture.

  • Validate enterprise architecture against the "keep it simple," "meet expectations," and "follow the rules" objectives.

  • Define the integration approach to integrate the IT governance model with the regular organization software development life cycle (SDLC)

  • Define the approach of incorporating policies, the security model, and the performance model within your applications.

  • Validate identified policies, the security model, and the performance model against the "follow the rules" objective.

When
  • Prioritize the business process implementation plan.

  • Based on the priority, define time-sensitive key milestones to finalize the product roadmap.

  • Consider the user acceptance phase and plan for incorporation of customer feedback as part of the product roadmap.

  • Define a timeline and milestones for technology components, product service implementation, and the deployment plan.

  • Consider different proof of concepts (POCs) and technical analysis on different advance technology components in the isolated technology lab environment before implementing in the production environment.

  • Define timeline and major milestones to incorporate regulatory policies plan and integrate with the product roadmap and the technology roadmap.

Technical Overview of SOA

Most of the time, there is a general misconception that SOA equals Web Services. However, as described earlier, SOA is an architectural concept that covers how to implement loosely coupled, distributed, lightweight shared services that can be consumed by internal and external applications for systems integration and executing different business processes. The Web Service is one of the vital components for implementing lightweight and loosely coupled services following the SOA model.

It is apparent that services are the main component of SOA-based applications. Now let's start with examining the service concept in the simplest way. Services with public interfaces are typically developed by organizations (service providers) and deployed on the network cloud to allow access to other applications/services (service consumers) as shown in Figure 4-2. Service integration can be performed asynchronously or synchronously.

Image

Figure 4.2    Service integration based on SOA

Key Components of Services

Now let's take a look at the implementation of services and their behavior in detail by focusing on their key features and key components. You need to follow these steps during the implementation of any qualified self-contained service that can maintain its own context and state:

1. Define public interfaces and contracts to enable integration with other applications and services.

2. Based on its scope, the service must be interoperable and support different protocols.

3. Use XML as the description of the service contract to make the service platform independent. The service can then be found using dynamic service discovery.

Figure 4-3 defines a service and demonstrates its key components. It also maps the service with a Web Service definition, since the Web Service is one of the most common ways of implementing SOA-based applications.

Image

Figure 4.3    Service definition and Web Service definition

XML is an open standard and is platform independent, so it becomes the platform to describe interoperable services, establish connections between services and consumers, and perform operations defined as XML messages over different types of protocols such as TCP/IP, HTTP(S), SOAP, SMTP, and any other proprietary protocols.

A service interface is a well-defined set of inbound and outbound contract definitions to allow integration by consumer applications and services performing defined operations.

A service message allows interaction between the service provider and service consumer by passing the required parameters of the interface using a defined communication protocol based on the service description. SOAP is a widely used XML-based protocol (especially for Web Services) that performs structured message-based information exchange in a distributed environment. A SOAP-based message consists of an envelope detailing the message framework describing the definition of the message and how to interact and process it; a header, which is optional and defines the application-specific information related to the SOAP message; a body containing the actual message; encoding rules defining application-defined data types and how to serialize them; and RPC representation, a convention that represents Remote Procedure Calls (RPCs) and responses.

A service description consists of the definition of the messages, types of parameters, and policies in a standardized format that can provide understanding of the service and how to invoke it. The Web Services Description Language (WSDL) facilitates the Web Service definition in a standard XML structured format that is available to the consumer. The WSDL file contains the interface definition that will be used to invoke and integrate with the Web Service and the binding information defining the Web Service URI.

Service registration and discovery is a platform for publishing/registering the definition of your services that is publicly available as a services repository. Consumers can then search for those services and invoke them. As the name suggests, Universal Description, Discovery, and Integration (UDDI) is a platform-independent, XML-based public and private registry on the Internet for Web Services available for consumers for the discovery.

Silverlight and SOA

I think you now are prepared to learn about the high-level SOA for the development of Silverlight-based RIAs. This section revisits some capabilities of Silverlight discussed earlier in the book that make it possible to architect, develop, and deploy service-oriented enterprise RIAs using Silverlight.

In general, to present the SOA concept for Silverlight RIAs, I refined the diagram depicting device-and platform-independent Enterprise 2.0 and Web 2.0 applications (Figure 3-7) as shown in Figure 4-4.

Image

Figure 4.4    SOA concept for Microsoft Silverlight–based RIAs

Figure 4-4 presents the high-level general architecture diagram for service-oriented, Silverlight-based Enterprise 2.0 and Web 2.0 collaborative RIAs.

Let's see how suitable Silverlight is for implementing such applications. The following four factors are key characteristics of SOA-based RIAs:

  • Device and platform-independent applications

  • Abstracted presentation layer (separated from the business service and data access layers)

  • Integration with platform-agnostic services

  • Modular and reusable

Device and Platform-Independent Applications

One of the key features of SOA is to architect device-and platform-agnostic, service-based applications. Silverlight allows us to develop browser-independent and operating system–independent RIAs and integrate platform-agnostic services to perform different business processes.

The "Device and Platform-Independent Rich Internet Applications (RIAs)" section of the diagram represents different types of RIAs that can be developed and deployed using Silverlight. As discussed earlier, Silverlight is a platform-agnostic technology and is compatible with all well-known web browsers and operating systems, which makes it a perfect match to implement the SOA concept for the development of RIAs.

Abstracted Presentation Layer

Silverlight is a subset of WPF that enables us to create an XML-based externalized and abstracted definition of the user interface. This Silverlight XAML-based user interface design allows us to separate the presentation layer and the business service and data access layers, which is a key feature for any SOA.

The "Abstracted XML Platform–Based Presentation Layer" section of the diagram represents WPF XAML–based Silverlight RIAs (containing XAML user controls and related code-behind assemblies). The XAML user control–based presentation layer does not include any kind of business logic. However, depending on the application design approach, the immediate managed code-behind file can include business logic and direct data access (the way we developed the My Album application in Chapter 2). It is recommended that SOA-based RIAs keep only validation logic within the immediate code-behind component. As shown in Figure 4-4, for SOA-based RIAs, the main business logic and data access code should be separated from the presentation layer by placing it in a reusable code library component or a server-based managed code assembly.

Integration with Platform-Agnostic Services

The integration of Silverlight with Visual Studio and thus integration with code-behind managed code makes it possible to implement modular and loosely coupled service components. Managed code enables seamless integration with Web Services and data feeds (such as RSS feeds) and makes it possible to use other cutting-edge technology such as LINQ for the data/content integration.

The "Enterprise 2.0 and Web 2.0 Application Environment Cloud" section of the diagram contains a set of Web Services published in the private or public Internet space.Silverlight-based RIAs can perform any business-related functionality or access to the available content in the secured environment within the same domain or cross-domain in a secured way via Web Services.

As represented in the "Services for Business Process and Content Integration" section of the diagram, public and private Web Services form the platform-agnostic gateway for secured business logic execution and content access, making them completely separated from consumer applications and services.

Modularity and Reusability

Silverlight Visual Studio integration allows easy development of modular and reusable class library components for the presentation layer, business service layer, and data access layer. These components can be reused across one or more Silverlight-based applications, making the Silverlight application architecture more flexible.

The "Abstracted XML Platform–Based Presentation Layer" section of the diagram represents reusable user controls in a code-behind class library. One or more Silverlight-based RIAs can reference these class libraries and decide between the in-package or on-demand deployment approach based on the application's need. During your application design time, it is important to break out your user interface design and functional components to adopt the modular design concept and introduce reusability and abstraction using the Silverlight class library concept and server-based application service development concept.

The "Services for Business Process and Content Integration" section of the diagram depicts the Public and Private Web Services interface serving as the "gateway." These services can leverage business process integration and content access using the library of service providers, custom business components, service agents for information transformation, data adapters, and different types of XML platform–based feeds.

SOA-Based RIAs: Seven Key Principles

Chapter 3 briefly discussed the seven key principles—usability, flexibility, simplicity, reusability, scalability, maintainability, and security—to develop, deploy, and distribute SOA-based abstracted, loosely coupled, collaborative RIAs as SaaS to the end users (see Figure 4-5).

Image

Figure 4.5    Seven key principles for building RIAs as SaaS

The main vision of the Silverlight technology is to support all seven key principles for building RIAs as services.

Usability

The ISO 9241-11 guidelines define usability as follows:3

Usability is the extent to which a product can be used by specified users to achieve specified goals with effectiveness, efficiency, and satisfaction in a specified context of use.

Business-enabled RIAs, being very user-centric, are focused on mainly three factors—users, users, and users—enabling Web 2.0 and Enterprise 2.0 concepts. As a result, in my list, usability is the first principle of any SOA-based RIAs empowering end users/customers.

In Chapter 1, we identified the five key detailed dimensions—availability, responsiveness, clarity, utility, and safety—of usability. We can consolidate these and create three higher-level dimensions—effectiveness, efficiency, and satisfaction—of usability that are also aligned with the preceding definition (see Figure 4-6). It is recommended you consider these three usability dimensions during the technology selection process and architecting/designing and implementing your application to provide the maximum customer satisfaction.

Image

Figure 4.6    Dimensions of usability

The effectiveness dimension of usability is a measure of how well end users can achieve the vision and goals through the services-based RIA containing a user-friendly user interface. The implementation of highly available ("Can I get to it?"), high-quality, and consistent service-based RIA makes it a highly effective application. The designers can bring consistency across the application by finding repeatable, usable patterns and implementing a common and consistent theme across the application. To improve effectiveness, it is also important to provide an easy search functionality and make it easy to navigate to a help feature to finish different functionalities.

The efficient dimension of usability is a measure of how fast you can achieve, perform, or execute an action by using the provided serviced-based, simplified RIA with its intuitive user interface. Highly responsive ("Is it fast enough?"), simplified, and high-clarity ("Can I figure it out?") RIAs are more efficient. It should not matter if end users are familiar (experienced) with the application or not. New end users should be in a position to learn the application with no or very little training. For quick execution, it is important to consider the total number of clicks and overall response time (factoring in different types of connectivity and different levels of users) to complete a particular task.

The satisfaction dimension of usability is a measure of how happy and satisfied end users are at the end of their interaction with the application in terms of achieving goals comfortably. Utility ("Does it have what I want?") and safety ("Is my identity and information secured?") are key factors to achieve maximum satisfaction. It is important to consider and analyze the audience of the application, learn the culture and expectations of potential customers, and provide a secured application platform to achieve their trust.

Flexibility

IEEE Standard 610.12 provides the following definition for flexibility:4

Flexibility is the ease with which a system or component can be modified for use in applications or environments other than those for which it was specifically designed.

After usability, flexibility is the next key principle for IT solutions, a requirement that allows those solutions to remain competent in a continuously changing global market. Implementing and giving flexibility in IT solutions empowers end users and enables organizations to cope with the changes in different dimensions of the market, end user expectation, and governance rules and regulations.

Figure 4-7 presents the main characteristics—platform independent, loosely coupled and customizable, and support for agility—of the flexibility principle that mainly cover all SOA aspects to provide a platform to implement decoupled IT solutions that can adopt the dynamic nature of the business easily. The characteristics of flexibility can drive achievement of other principles of SOA-based RIAs.

Image

Figure 4.7    Characteristics of flexibility

The platform-independent characteristic of IT solutions provides a flexible IT solution that can support all types of devices, browsers, and operating systems and helps to achieve the goal of "one solution for all." It is important to consider designing the user interface components to resize automatically based on the different device screen sizes and screen resolutions. By achieving this goal, the overall usability of the application and reusability of the user interface components will be improved.

The loosely coupled and customizable characteristics of the IT solutions helps organizations to develop distributed RIAs supporting a global and diversified community and the dynamic nature of the business. The following are key service-based application architecture principles that help to implement flexible, loosely coupled, customizable RIA solutions; they also can help to introduce "plug-in" functionality, which enables adding or detaching different services to or from the application and upgrading from the current version to a newer version of the service.

  • Modular and abstracted component design to develop decoupled presentation, business service, and data access layers

  • Externalization of resource definition and configuration to support globalization, localization, and integration with different environment setups

  • Open platform–based (e.g., XML-based) architecture to support unified communication and integration among different services and application layers

The support for agility characteristic of IT solutions defines the capabilities to cope with the continuously changing global marketplace. In the era of the Web 2.0

  • IT came within reach of most people across the world and became a part of their day-to-day lives in one form or another. The diversified global community in terms of geographic locations, culture, expectations, and abilities brings challenges to IT executives, who need to support the continuous increase of customer expectations and ever-changing requirements.

  • Globalization, digitization of information, and advance technology make the market very competitive and agile and also raise the issue of information overload.

  • In order to facilitate a secured IT solution platform in terms of identity management, information management, and organization management, global and country-specific regulatory rules and policies must be continuously improved.

Agile Software Development Life Cycle Model

The topic of the Agile SDLC model is vast enough for an entire book. However, for the purposes of this book, a summary of the Agile SDLC will suffice.

To support the dynamic nature of the market, it would be challenging for organizations to follow the traditional waterfall SDLC model to implement IT solutions. In order to provide faster, cheaper, and better products delivering high business value, organizations have to implement an optimized, diversified, agile, and cohesive IT organization model that can facilitate global and virtual environments and provide a flexible service-oriented technology platform to adopt changes in the technology and customer requirements.

The Enterprise 2.0 concept embraces the new concept of Agile SDLC.SOA-based RIAs, at the heart of which are lightweight, externalized, distributed, and loosely coupled application services, are flexible enough to support the Agile SDLC and thus the dynamic nature of the market and "time to market" principle.Figure 4-8 provides a high-level overview of the Agile SDLC.

Image

Figure 4.8    Agile SDLC Model

Agile software development is defined as follows:5

Agile Software Development methodologies generally promote a project management process that encourages frequent inspection and adaptation; a leadership philosophy that encourages team work, self-organization, and accountability; a set of engineering best practices that allow for rapid delivery of high-quality software; and a business approach that aligns development with customer needs and company goals.

As shown in the Figure 4-8, the Agile SDLC mainly follows an incremental and iterative-phased approach for software development. In the diagram, moving from left to right, the level of uncertainty and unknowns decreases. As you progress, say, from the "Proof of Concepts (PoCs) and Prototypes" phase to the "Testing" phase, the level of uncertainty and unknowns will be reduced, and the product release will be more stable and deployable.

The Agile SDLC implies working very closely and strategically with stakeholders and customers, and balancing expectations against the time line and business values to create a road map for the development of business-enabled RIAs. It is not necessary for the first release of the product to feature all requirements and meet all expectations. Instead, requirements and expectations are prioritized and delivered incrementally in a phased approach to deliver maximum business values and ROI.

Once the high-level scope of a particular release, based on prioritized requirements, is defined, the agile development model allows you to determine different iterations. Based on the quality of the requirements and understanding of those requirements and technology, the release life cycle may start with the development of different POCs and prototypes to finalize the scope of the release.

From the beginning of the product-specific release life cycle, customers, stakeholders, and quality assurance and IT governance teams are continuously involved to review product output and business process implementation and provide constructive feedback to the project team. At the end of every iteration, the project team will revisit and evaluate the received feedback and adjust the scope of the next iterations to incorporate them following a test-driven development (TDD) approach.

Simplicity

IEEE Standard 610.12 provides the following definition for simplicity:6

The degree to which a system or component has a design and implementation that is straightforward and easy to understand.

The concept of simplicity is relative, and with respect to IT solutions, it can vary user by user, organization by organization, and IT solution by IT solution.

Simplified, consistent applications are more usable, more accepted by end users, and tend to achieve more ROI. There is a widely popular software principle known as KISS (which originally stood for "Keep It Simple, Stupid") that emphasizes the importance of simplicity during the software design process. While we are on the edge of Enterprise 2.0 and Web 2.0, a new definition of the KISS principle is emerging that applies to both end users (customers) and enterprises: "Keep it Simple and Sustainable." Based on the revised KISS principle, simplicity can be defined as follows:

Simplicity is the level of easiness for

  • Targeted customers to understand and use the IT solution and services without or minimum training by providingconsistencyin the user interface design

  • Enterprises to design IT solutions and services, which areconsistentandsustainableby facilitating easy development, deployment, distribution, support, and maintenance

In order to achieve simplicity in IT solutions, during technology selection and architecting/designing and implementing your application, you need to consider two dimensions of the simplicity principle—consistency and sustainability—as shown in Figure 4-9.

Image

Figure 4.9    Dimensions of simplicity

The consistency dimension of simplicity brings unification in terms of user interface, application service, and component design for implementation and integration among different business processes. Pattern identification is a key factor to define consistent user interface components and provide simplified component and service definitions.

A consistent user interface within various modules of the same application or across applications makes them easy to understand and use, which improves the user experience and thus improves the usability of applications. Identification of commonality in different business processes by defining key patterns enables enterprises to define and develop a common library of lightweight application services, which makes them easy to support and maintain.

The sustainability dimension of simplicity presents ease of end-user training, maintenance, supportability, and upgradability of application services. The common library of lightweight and loosely coupled application services is easy to deploy, distribute, support, and upgrade.

Reusability

IEEE Standard 610.12 provides the following definition for reusability:7

The degree to which a software module or other work product can be used in more than one computing program or software system.

Based on the identified patterns and common functionalities among business processes, reusability can be introduced by following the modular and abstracted component design and with the development of lightweight, decoupled application services. The product team can also develop a set of templates and standards as well as follow best practices from industry experts as a part of the core framework to enable easy development, testing, and deployment.

If an IT solution is planned, documented, and implemented correctly, and built upon the right set of technology platforms and components, an organization can capitalize on a reusable, common set of lightweight, loosely coupled application services and components. In the long term, it can achieve maximum ROI in terms of improved productivity, efficiency, and maintainability as shown in Figure 4-10.

Image

Figure 4.10    Advantages of reusability

In the long term, with the development of reusable templates, reusable components, and reusable application services comes a significant improvement in productivity. With the available common set of template, component, and service libraries, the development and testing teams do not need to retest these existing components and services again and again. Eventually, this will allow development, testing, and deployment of new IT solutions based on the existing component and service libraries with less effort and in less time. This helps organizations to achieve the goal of "faster, better, and cheaper."

Reusability will also improve organization efficiency in terms of development, testing, and deployment of new IT solutions based on the component and service library by improving overall organization execution and IT solution quality, controlling cost, simplifying support and maintenance processes, and supporting the Agile SDLC.

The reusability of software components and services also eases the maintenance and support processes of organizations. With the development of reusable, lightweight, loosely coupled application services using a component library, it would be easy to deploy, distribute, and support such services. Version management and upgrades of reusable components and services would be easier in terms of testing, deployment, and distribution.

Scalability

Scalability is one of the most critical factors you need to consider when you plan for the development and deployment of Silverlight-based RIAs, because such applications usually deal with rich, large content and media files.

Scalability is a very broad subject with various definitions. Following is one such definition:8

Scalability represents the capability of increasing the computing capacity of a service provider's computer system and system's ability to process more user requests, operations, or transactions in a given time interval.

Scalability also deals with the performance criteria of IT solutions in executing different actions. Scalability represents the capabilities of application services (software) and deployed environments (hardware) to cope with increased user requests and data volume to provide the same or better performance.

Figure 4-11 shows the three key dimensions of the scalability—volume, software, and hardware—that need to be considered to develop and deploy IT solutions that can handle all types of demands and loads without having any impact on networks and connections.

Image

Figure 4.11    Dimensions of scalability

The volume dimension of scalability mainly focuses on various end users and data-related parameters. Application scalability and performance is highly dependable and measurable upon different user-and data-related factors such as data size, data volume, number of users, number of concurrent requests, number of transactions, and types of user requests.

The software dimension of scalability mainly focuses on the application design and implementation approach. If you have all types of required hardware, but the application and application services are not well designed and well implemented, the application may not be scalable enough to handle large-size data, high-data volume, a large number of users, many user requests, and a large number of transactions. It is important to consider various areas of software engineering such as memory management (including caching and object management), definition of data types, determination on the use of protocols for information exchange, client-side vs. server-side processing, data connection management, and security measure implementation based on IT governance and identity management standards.

The first dimension that most people think of when talking about the scalability is hardware.It is important for hardware configuration and implementation to align with the other two dimensions—volume and software—of scalability. Once enterprise architects determine the volume factor (including customer-related information, scope of the customers—internal or external customers—availability, and types of connectivity) and the software factor, the next thing to determine is the environment setup, which is done by defining the system architecture. During the process of defining the system architecture, you need to consider the organization's long-term vision in terms of future usage of systems, geographically diversified customers, identity management, IT governance rules and regulations, and security measures.

Figure 4-12 compares the horizontal scaling (scale out) and vertical scaling (scale up) approaches to improve the scalability of an application environment.

Image

Figure 4.12    Vertical and horizontal scaling to improve scalability

Vertical scaling, which is also known as scaling up, is an approach to improve scalability by improving an existing server configuration through the migration from low-end servers to high-end servers with multiple processors (CPU), high RAM, and more HDD space. In today's market, the virtualization concept is becoming more acceptable and popular. Virtual server technology makes the vertical scaling approach more practical, and thus it has become a part of the strategic technology direction for many organizations. At the same time, upgrading from 32-bit to 64-bit servers also scales up the environment and can provide significant improvement in application performance. The vertical scaling approach may end up in a single-point failure and is not a good approach for the applications that need to have high availability.

Horizontal scaling, which is also known as scaling out, is an approach to improve scalability by adding multiple servers for the same applications and applying the concept of server firms, caching, replication, server clustering, and load balancing. The horizontal scaling approach is also considered to provide high availability; since more than one environment is holding the application, it is possible to switch from one to another in terms of the failure of a specific environment.

Now the next logical question is, what is the best approach to achieve maximum scalability? Looking at the nature of Silverlight-based RIAs, a balanced approach is required to provide the right environment for highly scalable RIAs. It would not be acceptable for any organization to deploy enterprise solutions with high-end servers but single-point failure by implementing only the vertical scaling approach. At the same time, the low-end servers required to implement the horizontal scaling approach will not be appropriate for deploying high-performing and highly scalable RIAs, as such an environment doesn't enable integration of very large rich media files. The best approach is a balanced one: having high-end multiple servers facilitating high availability. The server configuration and number of servers required would be dependent on the overall application requirements.

Maitainability

IEEE Standard 610.12 provides the following definition of maintainability:9

(1) The ease with which a software system or component can be modified to correct faults, improve performance or other attributes, or adapt to a changed environment.

(2) The ease with which a hardware system or component can be retained in, or restored to, a state in which it can perform its required functions.

In other words, IT solutions that are easy to monitor and support are called maintainable IT solutions. Figure 4-13 shows two key dimensions of maintainability—supportability and monitoring—that need to be considered and predicated during the process of the development and deployment of RIAs.

Image

Figure 4.13    Dimensions of maintainability

Offshore outsourcing is becoming a critical cost-saving strategy for many organizations, and maintainability plays a critical role in the success of this strategy. It is important to consider the maintainability principle during the requirement analysis, design, and development phases, and processes to assist postdeployment support, maintenance, administration, and monitoring should be implemented.

The supportability dimension of maintainability is a measure of IT system quality and an organization's capabilities to provide postdeployment user support. An early consideration of supportability in the SDLC helps organizations to

  • Implement a proper level of error handling and instrumentation within the application. Proper error handling facilitates a user-friendly notification approach in case of any application errors. Instrumentation provides the capabilities of monitoring, tracing, and debugging applications postdeployment by implementing logging and reporting mechanisms integrated with enterprise applications.

    Use components created using best practices and patterns provided by industry leaders to standardize the enterprise-wide application implementation process. As an example, Microsoft Enterprise Library provides different types of application blocks (components) that can be used as core framework components to build enterprise application features. To facilitate standardized error management and instrumentation, enterprises can use the Microsoft Exception Handling Application Block, Logging Application Block, Policy Injection Application Block, and Validation Application Block, which are all part of the Microsoft Enterprise Library.

  • Define and develop required support tools and support processes that help the organization support team to identify, analyze, debug, and isolate problems and resolve them.

  • Develop required documentation such as user guides, training materials, technical documentation, FAQs, and instruction documents that are used to develop awareness and expertise among end users and organization support teams.

The monitoring dimension is all about being proactive in terms of predicting future problems and future end user needs, taking preventive actions to resolve problems before they actually appear, and enhancing applications to improve customer satisfaction. Thus the monitoring dimension helps organizations to maintain and improve the quality of their products. Instrumentation techniques for end-user application usage and the infrastructure environment are key for providing critical reports and implementing an effective monitoring process. End-user reports such as error reports, application usage statistics, application event management reports, and application performance analysis reports (performance counters, etc.) are helpful for understanding the application and user behavior during application execution, and assisting in problem resolution and future application quality improvements. Infrastructure environment reports such as CPU usage reports, memory usage reports, workload reports, user request reports, and response time reports can assist support teams in keeping the environment up and running; they also provide key information to enterprise architects on environment resource usage to help them determine how to improve scalability and availability.

Security

As markets become more digital and application services become more loosely coupled, the chances of vulnerability in every aspect of IT management increases. Organizations have to implement an IT governance model and security measures as part of their IT system implementation and maintenance life cycle.

Organizations can consider five dimensions—information security, identity management, software security, infrastructure security, and regulatory compliances—of IT security (see Figure 4-14) in implementing a security model as part of IT governance.

Image

Figure 4.14    Dimensions of security

The information security dimension of security plays a critical role since most interorganization and cross-organization business process execution has become electronic, and thus most information is available in digital format. Information security is mainly focused on the processes, standards, and implementation of information security measures to achieve confidentiality, integrity, and availability. The ISO/IEC Standard 27002 defines information security as the following:10

Information Security is described as the preservation ofconfidentiality(ensuring that information is accessible only to those authorized to have access), integrity(safeguarding the accuracy and completeness of information and processing methods), andavailability(ensuring that authorized users have access to information and associated assets when required).

The identity management dimension of security mainly deals with user management; it defines standard processes, policies, and administration tools to provide simplified user provisioning, domain management, role management, and subscription services to implement secured (possibly single sign-on), authorized, and role-based access to applications and services. Advance Enterprise 2.0 concepts, such as virtualization, remote access, and multiple device platforms for information access, and advanced Web 2.0 concepts, such as social-networking and RIAs, bring about different types of challenges to implement and maintain efficient and effective identity management systems. To support Enterprise 2.0 and Web 2.0 concepts, identity management also involves some innovative concepts such as federated identity management and OpenID (http://openid.net/foundation/) to simplify enterprise-level identity management processes and provide better user experience. These concepts support a common user-provisioning and access mechanism that enables users to access more than one cross-enterprise application and web site using the same user identification.

The software security dimension of security drives organizations to define security standards, policies, and measures to incorporate during the design, development, and quality assurance phases of IT system implementation. These measures are taken during the IT system implementation process to prevent postdeployment vulnerabilities.

The infrastructure security dimension of security is a key factor in providing a scalable, high-performing, secured environment for IT systems. The selection of hardware and the way it is deployed have an impact on the security provisions for IT systems. With cutting-edge capabilities such as virtualization, device platform-independent applications bring different infrastructure security challenges compared to traditional challenges. During the system architecture definition of IT systems, all required security measures along with possible future security impacts should be considered to provide a secured environment. Proper testing of the implemented infrastructure mimics the real world in an isolated lab environment to test real-world scenarios involving performance, network impact analysis, data capacity analysis, stress testing, and security testing to validate the implemented security measures.

Due to the impact of globalization and overall efforts to implement effective risk management policies, the regulatory compliance dimension of security is one of the key strategic components of the organization IT governance model. Organizations have to implement all possible measures, validation, and monitoring processes to confirm and validate the implementation and support of global and country-specific government and regulatory body rules and regulations that are related to risk management, data privacy, IT system performance, and security.

Microsoft Silverlight and the Seven Key Principles

You already know what makes Silverlight an enterprise-ready technology platform. Table 4-2 maps Silverlight's capabilities to the seven principles of SOA to prove that we can develop SOA-based Silverlight RIAs.

Table 4.2    Microsoft Silverlight and the Seven Key Principles of SOA-Based RIAs

Seven Principles of SOA Silverlight Capabilities
Usability (effectiveness, efficiency, satisfaction)
  • Silverlight allows easy development of simplified, rich user interface with the use of Visual Studio and Expression Blend.

  • .NET Framework 3.5 and WPF XAML–based user interface definition help the Silverlight platform to render 2D vector graphics, multimedia, animation, text, and rich data- bound user interface controls seamlessly and in an interactive and integrated fashion.

  • The Silverlight Deep Zoom feature provides the ability to smoothly present and navigate large amounts of visual information. The Silverlight framework and code-behind .NET enable design of decoupled presentation layer.

  • Support is provided for single and multibyte characters to accommodate localization.

  • Applications are lightweight (minimum client footprint), providing high-performance.

Flexibility (platform independent, loosely coupled and customizable, support for agility)
  • Silverlight provides a device-, browser-, and operating system– independent platform.

    XML-based user interface design makes it easy to customize.

  • .NET platform–based application development supports designing externalized and loosely coupled services.

  • The Silverlight application development platform supports WCF and Web Service integration via REST, WS*/SOAP, POX, RSS, and standard HTTP protocols.

  • Silverlight enables loosely coupled data-integration capabilities in asynchronous mode with the rich presentation layer.

  • Silverlight makes it easy to adopt changes.

Simplicity (consistency, sustainability)
  • Pattern-based, reusable Silverlight XAML–based user control library enables consistent simplified user interface development.

  • Applications are easy to deploy, support, and maintain.

Reusability (productivity, efficiency, maintainability)
  • Silverlight Application and Class Library templates allow creation of reusable user controls and managed code-based components, which can be stored in a common library.

  • Applications are easy to support and maintain due to common component library.

  • Support for Agile SDLC is enabled by rapid application development with the use of common components and services.

Scalability (volume, software, hardware)
  • The Silverlight platform supports data volume and hardware scaling to provide high performance with high workload.

  • Support for adaptive media streaming helps to improve the synchronization of media, providing high-performing media integration.

  • Silverlight supports object animation and embedded code-based ani-mation to provide high-performing graphics and animation support.

  • Silverlight applications can be developed to include background threading and asynchronous communication.

Maintainability (supportability, monitoring)
  • Managed code-based Silverlight applications are easy to support.

  • Rich user interface development is easy to understand and support.

  • The .NET platform enables regular instrumentation and other monitoring services to integrate with Silverlight applications.

Security (information security, software security, infrastructure security, regulatory compliance)
  • Support for digital rights management (DRM) for media streaming encourages enterprises to distribute digital media using Silverlight RIAs.

  • Silverlight supports policy-based application development and secured across-domain deployment

  • .NET-based service and data access layer implementation enables organizations to provide required information security and software security, and comply with regulatory policies.

Now let's briefly examine the key .NET enterprise features such as LINQ and externalization. To understand how to integrate these features and Web Services with Silverlight, we will create a small, dynamic Silverlight application in the section "Building a Dynamic Service-Oriented Silverlight Application." Later in Chapter 5, we will capitalize on these design and implementation concepts while building the Enterprise Training Portal RIA using Silverlight.

LINQ

LINQ, which is part of .NET Framework 3.5, is a way to query data natively. In other words, the data is held as an object and that object is queried, and it doesn't matter what the source of that data is. Figure 4-15 defines the high-level LINQ architecture.

Image

Figure 4.15    LINQ architecture

As shown in Figure 4-15, LINQ mainly consists of LINQ language extensions and LINQ query providers. With the release of Visual Studio 2008 and .NET Framework 3.5, programming languages such as Visual Basic and C# support LINQ language extensions. Programming languages that support LINQ language extensions enable developers to implement standard query definitions using different LINQ query providers such as standard query operators, lambda expressions, expression trees, expression methods, object initializers, and anonymous typed and implicitly typed local variables. LINQ query providers manage application LINQ queries and resulting data marshalling between the native data source and in-memory enumerable types. You can write LINQ query expressions to query different types of data source platforms that support implementations of IEnumerable or IEnumerable<T>.

  • LINQ to XML allows you to query XML using SQL-like queries and add/remove/modify XML document nodes in memory. For detailed information, visit http://msdn.microsoft.com/en-us/library/bb387098.aspx.

  • LINQ to SQL enables you to manage a relational database as an object model to build effective query expressions. This is achieved with an object-relational mapping that translates the query into a SQL query. LINQ to SQL defines two core parameterized attributes, [Table] (to associate with the SQL table and view) and [Column] (to associate with the SQL column), which indicate which CLR types and properties correspond to external SQL data. For detailed information, visit http://msdn.microsoft.com/en-us/library/bb386976.aspx.

  • LINQ to Entities allows you to develop strongly typed queries against the Entity Data Model (EDM) object using the object services infrastructure. The ObjectContext class is the primary class for interacting with an EDM. You can construct ObjectQuery instances through the ObjectContext. Entity objects returned by ObjectQuery are tracked by the ObjectContext and can be updated by using the SaveChanges() method. For detailed information, visit http://msdn.microsoft.com/en-us/library/bb386964.aspx.

  • LINQ to DataSet enables you to query the data cached in a DataSet object. You can build LINQ to DataSet–based query expressions using the DataRowExtensions and DataTableExtensions classes of ADO.NET. For detailed information, visit http://msdn.microsoft.com/en-us/library/bb386977.aspx.

  • LINQ to Objects enables you to define query expressions to retrieve data from any IEnumerable or IEnumerable<T> collection. For detailed information, visit http://msdn.microsoft.com/en-us/library/bb397919.aspx.

There are numerous concerns related to the implementation of enterprise-level security and traditional layered enterprise architecture with the use of LINQ for enterprise applications, since you can directly query the data source from your application. However, when used with a properly architected multilayered (presentation, business service, data access layers) enterprise solution, LINQ can help you to build a secured, SOA-based enterprise application.

Externalization

Implementation of the externalization design concept plays a critical role for providing modularity and flexibility in your service-oriented applications. Externalization can be implemented in all three layers—presentation, business service, and data access —of your SOA-based applications. Tight integration of an XML-like open platform with .NET enables you to implement loosely coupled presentation and service layers and data-platform-agnostic data access layers.

Silverlight helps to facilitate externalized customization and configuration of user interface styles and definition by enabling WPF XAML–based, XML platform–based user interface definition with support for localization and globalization features. You can change the XAML-based user interface definition without recompiling. The Silverlight project can then be redeployed with the new user interface definition. You need to recompile the application only when you have to change the code-behind .NET managed code portion. Integration with the .NET managed code-behind makes it possible to create dynamic user interface definitions based on repeatable user interface patterns such as horizontal or vertical tabs. In our sample application, we will create a number of tabs and the title of the tabs dynamically based on an XML configuration file definition.

XML-based configuration files enable externalized configuration of services, data platforms, and infrastructure to allow dynamic runtime integration with other required services and data platforms. This helps to make SOA-based RIAs data-platform and infrastructure-environment agnostic.

Building a Dynamic Service-Oriented Silverlight Application

Now let's build a service-oriented sample Silverlight application with a dynamic user interface and content population to explore different enterprise features (such as externalization, LINQ, Web Services, and custom user controls).


Note The main focus of this simplified UI-based Silverlight application is to demonstrate the enterprise capabilities of Silverlight. In a real implementation, this type of application will have a rich user interface and may use different types of Silverlight WPF user controls.


Design Concepts

As shown in Figure 4-16, we will implement an externalized Silverlight user interface by developing dynamic tabs (horizontal and vertical) based on an XML-based tab definition and will integrate tab-specific content at runtime based on an externalized data storage definition.

Image

Figure 4.16    Building loosely coupled Silverlight user interface

Loosely Coupled Silverlight User Interface

The use of tabs is one of the most common practices in modularizing web sites. Externalized definitions of tabs (defining how many tabs are required and the direction and attributes of each tab) help to introduce reusability of tab control components across different applications and have flexibility within the application to create and configure tabs dynamically.

To understand how to develop a loosely coupled Silverlight user interface, we will develop a Silverlight application called SmartTabs. Required tabs and their behavior are defined in an externalized XML file—tabDefinition.XML. The getTabDefinition Web Service, which uses LINQ, is employed to get the information from the tabDefinition.XML file. Based on the information received from the XML file, we will populate a Grid to create tabs and related content areas with the horizontal or vertical tab orientation at runtime.

Tab Content Integration

The tabDefinition.XML file also contains the data source information for each tab along with the tab's attributes. The getTabContents Web Service with the use of LINQ will connect to the data source (XML file, SQL Server database, or any other data source) and retrieve the content of the particular tab. The retrieved content can be mapped to the Silverlight controls (Image, TextBlock, MediaElement, etc.) for each tab to populate the tab content. The externalization of the data platform definition makes the application data platform independent, and end users always get the latest content.

We will implement the simplest scenario where all tab content is stored within a single XML file—tabContents.XML. In a more complicated and practical scenario, the content of every tab is stored at different data sources with different data types. It is important to convert the contents into the required data types before they get mapped to the Tab Content's Silverlight controls.

Developing the Dynamic User Interface

The SmartTabs Silverlight web site project creates the Application class (app.xaml and app.xaml.cs) and the Page class (page.xaml and page.xaml.cs) by default. The Page class represents the main user interface and is derived from UserControl. We will add only the StackPanel layout user control with the Name masterHolder as the master container (as shown in the following code) to host tabs and tab content as its child elements at runtime.

<Grid x:Name="LayoutRoot" Background="White">
       <StackPanel x:Name="masterHolder" Orientation="Vertical"></StackPanel>
</Grid>

Adding Custom Silverlight User Controls

Silverlight UserControls are a basic unit for the reuse of the XAML-based user interface and code-behind within the application and across applications. For our SmartTabs project, we need to add two custom Silverlight UserControls: tabDefinition, which defines tabs, and tabContent, which presents tab-specific content.

The tabDefinition UserControl contains two StackPanel layout controls within the Grid layout control. The tabHolder StackPanel control holds a number of tabs based on the tabDefinition.xml file. The default Orientation attribute of the tabHolder StackPanel is set to Vertical. However, it would be changed to Horizontal or Vertical based on the definition in the tabDefinition.xml file at runtime. The contentsHolder StackPanel control holds tab-specific content from the defined data source, which in our case is the tabContents.XML file. Instances of tabContent will be placed for each tab to represent tab-specific content within the contentsHolder StackPanel user control. Following is the resulting code snippet from tabDefinition.xml:

<Grid x:Name="LayoutRoot" Background="White">
      <StackPanel x:Name="tabsHolder" Orientation="Vertical"
         HorizontalAlignment="Left">
      </StackPanel>
      <StackPanel x:Name="contentsHolder" Orientation="Vertical"
         HorizontalAlignment="Left">
      </StackPanel>
</Grid>

The tabContent user control contains a Grid layout control to display content received from the defined data source, as shown in the following code snippet. The tabContent will include three controls—Image, HyperlinkButton, TextBlock—to display the content.

<Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinitionHeight="*"/>
            <RowDefinitionHeight="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinitionWidth="*"/>
            <ColumnDefinitionWidth="*"/>
        </Grid.ColumnDefinitions>
        <Image Grid.Column="0" Grid.RowSpan="2" x:Name="icon"

            HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None"
            Margin="10,0,8,0" />
        <HyperlinkButton Grid.Column="1" Grid.Row="0" x:Name="title"
               HorizontalAlignment="Stretch" VerticalAlignment="Bottom"
               FontSize="13" FontWeight="SemiBold" FontFamily="Arial"
               Foreground="#FF0472C7"/>
        <TextBlock TextWrapping="Wrap" Grid.Column="1" Grid.Row="1"
               x:Name="details" HorizontalAlignment="Stretch"
               VerticalAlignment="Stretch"
               FontSize="13" Foreground="#FF000000" FontFamily="Arial"/>
</Grid>

Code-Behind to Generate Tabs Dynamically

Upon adding the tabDefinition and tabContent UserControls, the corresponding XAML and code-behind files are automatically generated.

tabDefinition.xaml.cs is the core code-behind class that performs all the required actions to create tabs dynamically and populate content in each tab using Web Services and LINQ.

Before we get into the details of this core code-behind class, you need to add references to the following .NET library components:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.IO.IsolatedStorage;
using System.IO;
using System.Net;
using System.Windows.Media.Imaging;

You also need to declare variables as shown in the following code. The comments are self-explanatory.

namespace Silverlight_smartTabs
{
    public partial class tabDefinition : UserControl
    {
        //String array to hold tab contents
        public string[,] contents = new string[100, 5];
        //In-memory image cache for tab's rollover effect
        BitmapImage[] imgOn = new BitmapImage[11];
        BitmapImage[] imgOff=new BitmapImage[11];
        //Image array for tab creation
        public Image [] tab = new Image[11];
        //String to hold information about tab orientation
        public string tabOrientation;
        //Int to hold tab count(number of tabs but not more than 10)
        public int tabCount = new int();

Some assumptions were made and a few limitations kept to simplify the development process. The main assumption is that the number of tabs will not be more than ten. The rest of the variables are defined so that they can support a maximum of ten tab definitions. Of course, you may like to make it more generic and not tie any limitations to this application.

Web Service Integration to Get Tab Definition XML File

As a part of the constructor of the tabDefinition class, we need to read the tabDefinition.xml file by calling the Web Service getTabDefinition, and then, once we've read it successfully, raise an event, getTab_getTabDefinitionCompleted. The code snippet of the constructor is shown here:

public tabDefinition()
{
  InitializeComponent();
  //Here we call getTabDefinition Web Service and set up tab images for
  //mouseOver and normal state
  getTabDefinition.getTabDefinitionSoapClient getTab = new
     Silverlight_smartTabs.getTabDefinition.getTabDefinitionSoapClient();
  getTab.getTabDefAsync();
  getTab.getTabDefCompleted +=new
    EventHandler<Silverlight_smartTabs.getTabDefinition
    getTabDefCompletedEventArgs>
  (getTab_getTabDefCompleted);
}

The getTab_getTabDefinitionCompleted event will call the processTab() method and pass the retrieved XML file as a string to create tabs based on an XML-based tab definition and then populate the respective content.

void getTab_getTabDefCompleted(objectsender,
    Silverlight_smartTabs.getTabDefinition.getTabDefCompletedEventArgs e)
{
  //Call to processTab method
  processTab(e.Result.ToString());
}

Defining Tabs Using LINQ

With the use of LINQ, the processTab(string sXML) method will process the XML file (the returned tabDefinition.xml file), create the required tabs, and populate the content in the following steps:

1. Load the retrieved XML file to the XDocument object to process later using LINQ:

XDocument xDoc = XDocument.Parse(sXML.Remove(0,3));

For your reference, the following is the retrieved tabDefinition.xml file:

<?xml version="1.0" encoding="utf-8" ?>
<tabs orientation="Horizontal" count="4">
<tab id="1">
  <imgOff>http://localhost:4353/Silverlight_smartTabs_Web/tabImgs/1.jpg</imgOff>
  <imgOn>http://localhost:4353/Silverlight_smartTabs_Web/tabImgs/o1.jpg</imgOn>
</tab>
<tab id="2">
  <imgOff>http://localhost:4353/Silverlight_smartTabs_Web/tabImgs/2.jpg</imgOff>
  <imgOn>http://localhost:4353/Silverlight_smartTabs_Web/tabImgs/o2.jpg</imgOn>
</tab>
<tab id="3">
  <imgOff>http://localhost:4353/Silverlight_smartTabs_Web/tabImgs/3.jpg</imgOff>
  <imgOn>http://localhost:4353/Silverlight_smartTabs_Web/tabImgs/o3.jpg</imgOn>

</tab>
<tab id="4">
  <imgOff>http://localhost:4353/Silverlight_smartTabs_Web/tabImgs/4.jpg</imgOff>
  <imgOn>http://localhost:4353/Silverlight_smartTabs_Web/tabImgs/o4.jpg</imgOn>
</tab>
</tabs>

2. The XML file contains tabs as the root node and orientation and count as attributes defining the required orientation of the tab and total number of tabs to create, respectively. Now we use LINQ to XML to get the tab orientation and tab count from the in-memory XML file loaded as xDoc and use proper data-type conversion to convert these values into the string and integer data types.

//Use LINQ to XML to get info about tab orientation and tab count(no. of tabs)
var tabinfo = from t in xDoc.Descendants("tabs")
             select new
             {
               ori = t.Attribute("orientation").Value,
               cnt = t.Attribute("count").Value,
             };
foreach (var itm in tabinfo)
{
    tabOrientation = itm.ori.ToString();
    tabCount= int.Parse(itm.cnt);
}

3. The retrieved XML file also defines images to provide some visual impact on MouseEnter and MouseOut events on the tabs. We will cache all images to improve performance using LINQ to XML, and then store images in a BitmapImage object instead of relying on the browser's cache. Here imgOn and imgOff are BitmapImage arrays. The Uri object is used to pass the absolute Uri related to the image to locate the image and store it as a BitmapImage object to the memory. Following is the code snippet that does all this:

//Use of LINQ to XML to store image Uris to BitmapImage arrays for
//mouseEnter and mouseOut images
var tabinfo = from t in xDoc.Descendants("tab")
select new
     {
       id = t.Attribute("id").Value,
       imgOff= t.Element("imgOff").Value,
       imgOn = t.Element("imgOn").Value,
      };
foreach (var itm in tabinfo)
  {
  //Image allocation. imagOn is an image for MouseEnter,
    //imgOff is default image
    imgOn[int.Parse(itm.id)] = new BitmapImage(new_Uri(itm.imgOn));
    imgOff[int.Parse(itm.id)] = new BitmapImage(new Uri(itm.imgOff));
  }

Creating Tabs at Runtime

Now that we have all the information about the required tabs available, it's time to build the dynamic tab page. For that, we call the buildTab() method at the end of the processTab() method. The buildTab() method will set the tab orientation and then create the required tabs dynamically as shown in the following steps:

1. Set the tab orientation and set up the tabHolder and contentsHolder controls accordingly. Based on the value stored in the tabOrientation variable, we need to set orientation of the tabHolder StackPanel object to either Horizontal or Vertical.

  • If tabs need to be vertical, we need to define two columns in the Grid using the ColumnDefinition object and ColumnProperty of the Grid object; using the ColumnProperty and SetValue properties, the tabHolder StackPanel is placed in Column 0 of the Grid object, and the contentsHolder StackPanel is placed in Column 1 of the Grid object.

  • If tabs need to be horizontal, we need to define two rows in the Grid using the RowDefinition object and RowProperty of the Grid object; using the RowProperty and SetValue properties, the tabHolder StackPanel is placed in Row 0 of the Grid object, and the contentsHolder StackPanel is placed in Row 1 of the Grid object.

Following is the code snippet for setting tab orientation:

//Set orientation of tabholder stackpanel based on tabOrientation value
if (tabOrientation.ToUpper() == "VERTICAL")
{
  tabHolder.Orientation = Orientation.Vertical;

  //Based on orientation, changes are needed in the grid layout
  ColumnDefinition c1 = new ColumnDefinition();
  ColumnDefinition c2 = new ColumnDefinition();
  LayoutRoot.ColumnDefinitions.Add(c1);
  LayoutRoot.ColumnDefinitions.Add(c2);
  //We put the tabHolder stackpanel in column0 and the contentsHolder
  //incolumn1
  tabHolder.SetValue(Grid.ColumnProperty, 0);
  contentsHolder.SetValue(Grid.ColumnProperty, 1);
}
else
{
tabHolder.Orientation = Orientation.Horizontal;
//Based on orientation, changes are needed in the grid layout
RowDefinition r1 = new RowDefinition();
RowDefinition r2 = new RowDefinition();
LayoutRoot.RowDefinitions.Add(r1);
LayoutRoot.RowDefinitions.Add(r2);
//We put the tabHolder stackpanel in row 0 and the contentsHolder
//in row 1.
tabHolder.SetValue(Grid.RowProperty, 0);
contentsHolder.SetValue(Grid.RowProperty,1);
}

2. Now that the tabHolder and contentsHolder StackPanel controls are properly laid out, we are all set to create the number of tabs based on the value of the tabCount variable (earlier populated from the tabDefinition.xml file). As shown in the following code snippet, first you assign the default image, and then add it as part of the child collection of the tabHolder StackPanel control:

//Create tabs in the tabHolder Stackpanel
for (int count = 1; count < tabCount + 1; count++)
{
  //Image allocation
  tab[count] = new Image();
  tab[count].Stretch = Stretch.None;
  tab[count].Source = imgOff[count];

//Add to the tabholder stackpanel
  tabHolder.Children.Add(tab[count]);
}

3. Now let's set up the MouseEnter event for each tab to provide a visual effect. The following code example assigns the MouseEnter event handler for tab1:

//Assigning eventhandler for mouseEnter event,
//using try catch block if tabs are less than 10
int index = 1;
try
{
  for(index=1;index<11;index++)
    if (index==11)
      break;
    else
    {
      tab[index].MouseEnter += new MouseEventHandler(tab_MouseEnter);
    }
}
catch (NullReferenceException e)
{
  //Be silent, do nothing
}

We want to have a different image appear when the mouse enters a particular tab area. In order to achieve this, we must set the current tab image to the image stored in the imgOn collection. The rest of the tab images should be set back to the corresponding image stored in the imgOff collection, which we will achieve by calling the resetTabs() method. The following code example sets the first tab image from the imgOff type image to the imgOn type image using the Source property:

//Method called upon tab_mouseEnter event
void tab_MouseEnter(object sender, MouseEventArgs e)
{
  Image tabRef = (Image)sender;
  int tempId = int.Parse(tabRef.Name);
  resetTabs(empId);
  buildContents(tempId);
  tab[tempId].Source = imgOn[tempId];
}

You need to call the resetTabs() method upon every MouseEnter event to reset all images to the default image type—imgOff—as shown in the following code snippet:

//resetTabs method for proper tab mouseOver and out effect
public void resetTabs(int tabId)
{
  for (int index = 1; index < tabCount + 1;index++)
  {
    //Skip selected tab
    if (index == tabId)
     continue;
    tab[index].Source = imgOff[index];
  }
}

Once the selected tab image is properly set up, you need to call the buildContents() method to populate the selected tab with the appropriate content. You'll see how to use this method in the section "Populating Tab Content."

Code-Behind to Populate Tab Content

At this point, we have created the required number of tabs dynamically at runtime based on the external XML file definition. We have also set up the proper events to implement the visual impact on the tab selection. Now we can populate the tab content area for each tab with content.

Web Service Integration to Get Tab Definition XML File

At the end of the buildTab() method, we will call the processContents() method to read the tabContents.xml file by calling the getTabContents Web Service. The code is very similar to that for reading and processing the tabDefinition.xml file for tab creation:

//Call Web Service to get tab contents as XML
publicvoidprocessContents()
{
  //HerewecallthegetTabContentsWebServiceandreceiveXMLthatwill
  //definetabcontents
  getTabContents.getTabContentsSoapClientgetContent = new
     Silverlight_smartTabs.getTabContents.getTabContentsSoapClient();
  getContent.getTabConsAsync();
  getContent.getTabConsCompleted += new
     EventHandler<Silverlight_smartTabs.getTabContents.
     getTabConsCompletedEventArgs>(getContent_getTabConsCompleted);
}

Defining Tab Content Using LINQ

Once the tabContents.xml file is read successfully, we raise an event, getContent_getTabConsCompleted, as shown in the following code snippet. Here we are using LINQ to read the XML file and store it in the contents string array for future use to display the appropriate content based on the selected tab.

//Parsing XML and assigning its value to diff. object which will be used to
//make up tab contents later
void getContent_getTabConsCompleted(object sender,
   Silverlight_smartTabs.getTabContents.getTabConsCompletedEventArgs e)
{
  int i = 0;
  //Use of LINQ to XML to parse XML string
  XDocument xDoc = XDocument.Parse(e.Result);
  //Parsing of each tab's contents
  var tabcontent = from t in xDoc.Descendants("content")

    select new
    {
id = t.Attribute("tabid").Value,
title = t.Element("title").Value,
hlink = t.Element("hlink").Value,
img = t.Element("img").Value,
      desc = t.Element("desc").Value,
    };
   //Storing above parsed values to contents string array
   foreach (var itm in tabcontent)
   {

    i++;
    contents[i, 0] = itm.id;
    contents[i, 1] = itm.title;
    contents[i, 2] = itm.hlink;
    contents[i, 3] = itm.img;
    contents[i, 4] = itm.desc;
  }
}

The following is a snapshot of the tabContents.xml file for your reference:

<?xml version="1.0" encoding="utf-8" ?>
<tabData>
<content tabid="1">
  <title>Tab 1</title>
  <hlink>http://technologyopinion.com</hlink>
  <img>http://localhost:4353/Silverlight_smartTabs_Web/image1.png</img>
  <desc>Tab 1 Description</desc>
</content>
<content tabid="2">
   <title>Tab 2</title>
   <hlink>http://technologyopinion.com</hlink>
   <img>http://localhost:4353/Silverlight_smartTabs_Web/image2.png</img>
   <desc>Tab 2 Description</desc>
</content>
<content tabid="3">
  <title>Tab 3</title>
  <hlink>http://technologyopinion.com</hlink>
  <img>http://localhost:4353/Silverlight_smartTabs_Web/image3.png</img>
  <desc>Tab 3 Description</desc>
</content>
<content tabid="4">
  <title>Tab 4</title>
  <hlink>http://technologyopinion.com</hlink>
  <img>http://localhost:4353/Silverlight_smartTabs_Web/image4.png</img>
  <desc>Tab 4 Description</desc>
</content>
</tabData>

Populating Tabs with Content

For every MouseEnter event of the tab, we need to populate the appropriate tab with content, which we can achieve by calling the buildContents() method. First we clear existing selected tab content by calling the Clear() method of the contentHolder control. Then based on the selected tab's ID, tabID, we create the tabContent object based on the tabContents.xml file, assign the retrieved image to the Image control (with the name icon), assign retrieved title hyperlink information to the HyperlinkButton control (with the name title), and assign a description to the TextBlock control (with the name details).

The following is the code snippet of the buildContents() method:

//Based on getContent_getTabConsCompleted, actual implementation of each
//tab's contents
public void buildContents(int tabId)
{
  //Clear any previous contents
  contentsHolder.Children.Clear();
  //Set values based on tabId from contents string array(which we constructed
  //in "getContent_getTabConsCompleted")
  //Need to loop through whole array

for (int i = 1; i < 101; i++)
{
   if (contents[i, 0] == null)
     break;
   else if (int.Parse(contents[i, 0]) == tabId)
   {
     //Create tabContent object from userControl "tabContent.xaml"
     tabContent tabConts = new tabContent();
     tabConts.title.Content=contents[i,1];
     tabConts.title.NavigateUri = new Uri(contents[i, 2]);
     BitmapImage bmp= new
        BitmapImage (new Uri (contents[i,3],UriKind.RelativeOrAbsolute));
     tabConts.icon.Source = bmp;
     tabConts.details.Text = contents[i, 4];
     contentsHolder.Children.Add(tabConts);
    }
  }
}

Both Web Services getTabDefinition and getTabContents are very straightforward, so the code is not shown in the book. However, you can download the complete project from the Source Code page on the Apress web site (http://www.apress.com).

Now if you run the project, four tabs (horizontal or vertical) will be created dynamically based on the XML file definition and displayed, as shown in Figure 4-17.

Image

Figure 4.17    Horizontal and vertical dynamic tabs

Summary

This chapter is considerably weighty, since it focused mainly on defining the SOA and its key concepts and principles. The enterprise leadership and technology teams need to understand and consider the SOA concept and align their technology and product roadmaps before implementing key IT systems to achieve long-term benefits.

The SOA concept aligns three organizational strategic components—product roadmap, technology roadmap, and IT governance model—to implement externalized, distributed, shared, and loosely coupled service-based RIAs and deploy them as SaaS, enabling Enterprise 2.0 and Web 2.0 concepts in the agile mode. The SOA-based application services will help organizations to achieve three key basic concepts—meet expectations, keep it simple, and follow the rules—vital for developing business-enabled RIAs and transforming IT organizations to move from cost center to profit-making center in the long term.

SOA does not mean just Web Services. SOA is an architectural concept describing how to implement loosely coupled, distributed, lightweight shared services to enable IT systems integration. Usually Web Services become the heart of the SOA implementation for the RIAs. In this chapter, we focused especially on defining the architecture of Web Services.

Since .NET Framework is the core platform for building Silverlight-based RIAs, Silverlight technology can support the seven key principles—usability, flexibility, simplicity, reusability, scalability, maintainability, and security—for building RIAs as services. The following four factors are key characteristics of SOA-based RIAs developed using Silverlight:

  • Device-and platform-independent RIAs

  • Abstracted presentation layer(separated from the business service and data access layers)

  • Integration with platform-agnostic services

  • Modular design and reusable component and service libraries

You learned how Silverlight supports enterprise-level features such as integration with Web Services, LINQ, externalization, use of Silverlight custom user controls, and dynamic creation at runtime of the user interface based on an externalized tab definition.

The next chapter will extend the lessons you've learned by taking you through the implementation of an enterprise-level, service-oriented, Silverlight-based RIA. We will take the My Album RIA developed in Chapter 2 as a base and migrate to the Enterprise Training Portal RIA so you can understand how to implement the SOA concept for Silverlight-based RIAs. During this exercise, you will learn in detail how to integrate different key .NET technology components such as LINQ, WCF and Web Services, XML, and SQL Server with Silverlight. The chapter will also highlight some key capabilities of Silverlight such as development of reusable components using Application and Class Library templates and the Deep Zoom functionality to improve usability by improving the user experience.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.55.18