This action might not be possible to undo. Are you sure you want to continue?
In the same week .NET 3.5 is released I get round to starting an article on .NET 3.0! So it'll only be another year or so before I manage to get to 3.5. In fact it will be sooner but back to 3.0 for the moment. Most of the classes in the .NET Framework version 2.0 are unchanged in 3.0/3.5. The key differences for .NET 3.0 are new libraries that offer completely new sets of functionality. There are four main components: Windows Presentation Foundation (WPF) is an entirely new UI technology based on the DirectX engine which facilitates the creation of vector based user interfaces rather than the conventional Windows bitmap based UI. WPF, it is claimed, is the platform for the next generation of interfaces facilitating UIs with built in capabilities to utilise this vector basis to deliver scaling, animation media, styling and 3D visualisation to deliver true business benefits. Windows Workflow (WF) is an engine for building applications with workflow. WF serves as the kernel of workflow, handling threading, persistence and other plumbing tasks. WF brings a consistent, component-oriented philosophy to workflow and is already at the core of Microsoft's business in products like SharePoint. Windows Communication Foundation (WCF) is a unified framework for machine to machine and process to process communication. WCF brings together the capabilities of various technologies into a common, integrated programming model. These technologies include Web Services (traditional and latest standards compliant versions thereof), enterprise services, remoting, and Microsoft Message Queue (MSMQ). WCF is designed to be the principal Microsoft platform for systems utilising the increasingly popular Service Oriented Architecture (SOA). Windows CardSpace is the name for a new technology in the .NET Framework 3.0 that simplifies and improves the safety of accessing resources and sharing personal information on the Internet. In this article I'll look in a little more theoretical detail at the first 3 of these 4 new components. In later articles I hope to dig a little deeper into the practicalities of using these new technologies. The main reference for this article is Professional VB 2005 with .NET 3.0 by Evjen et al.
Windows Presentation Foundation
WPF is based more on the HTML declarative model than Windows Forms model (for example). The idea is that you can use a declarative model to design your UI and then use that model for a desktop or web version of your application. WPF uses XML to declare the UI elements, relying on a standard known as the eXtensible Application Markup Language (XAML). Existing web and windows forms controls are based on raster graphics – collections of points on a surface that represent an image. The alternative approach is vector graphics, where a vector is a line with a point of origin that continues forward in space from that point of origin. Rather than being based on a collection of points, vector graphics are based on a series of vectors. Vector graphics allow you to create great looking UIs, but are more processor hungry, as we've seen with the increasing system requirements (particularly as regards graphics cards) with the Vista operating system with which the WPF libraries were released. WPF is based on Microsoft's DirectX technologies.
What do you need to build WPF Applications
WPF was released with Windows Vista so if this is your OS you are ready to go with regard to the Framework. If not you'll need the .NET 3 (or 3.5) runtime package for starters. Everybody will then need the Windows Vista SDK to start building WPF applications. Unfortunately it doesn't go as far as completely upgrading VS.NET 2005 to enable you to build WPF and other .NET 3.0 applications. Until you have a copy of VS2008 (just released in RTM form at the time 1
of writing so you may have a copy already) developers will need to get their hands a little dirty on the command line. Saying that, there are Visual Studio extensions for WPF/WCF but these are Community Technology Preview, and shall not exceed this level.
XAML and WPF
XAML is a markup based protocol. Similar to SOAP and several other XML-based formats, the XAML specification defines a potentially open standard for describing user interface elements. WPF is Microsoft’s implementation of this standard across 2 XML namespaces, one focussed on the definition of XAML and the 2nd focussed on WPF's implementation of the XAML specification (the WPF extensions). It is important to note that the XAML namespace can, and is, used for things other than WPF, e.g. WF. XAML is defined as a language consisting of a collection of elements, attributes and related objects. These objects are referenced from the XAML namespace, which by convention precedes each class with an "x:". WPF extends and maps these declarative structures back to .NET, using specific classes that are part of the .NET 3 System.Windows namespace. There are 3 categories of XML statement to be found within the XML namespace: attribute, markup extension and XAML directive. Attributes I'm sure you are already familiar with – these are the properties that can be associated with an XML node. Markup extensions correspond to the 'eXstensible' of the XAML acronym. A markup extension can be used to create an XML node or a collection of XML attributes. XAML directives allow placement of procedural code or data within XAML code. Everything else you see in the XAML file belongs to the 2nd namespace which defines the WPF extensions. We'll very briefly look at some of the core elements of this namespace. First up is the Application object which is required by all WPF applications and represents the application to the CLR. It is the primary process and is an instantitation of a class in the System.Windows namespace. In fact VB provides the underlying application object so you may not even need to deal with this. Behidn the scenes however the Application definition references Window and Page object. In your Window definition you would define the interface of your application. As a basic example you might give your Window a title, define its size and define a grid so you could reference specific points in the window, perhaps dispay a button you could code against. Then you need to write the partial class to react against the button click event raised. Basic WPF example:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" StartupUri="WPFWindow.xaml" /> <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WPFWindow" Title="Hello, WPF Window!" Height="300" Width="300"> <Grid> <Button Margin="100,100,100,100" name="btnHello" Click="btnHelloClick">Press Me</Window> </Grid> Partial Public Class MainWindow Inherits System.Windows.Window Public Sub New() InitializeComponent() End Sub Public Sub btnHelloClick(ByValSender As Object, ByVal e As System.Windows.RoutedEventArgs) btnHello.Content = "Hello!" System.Windows.MessageBox.Show("Hello!") End Sub
Controls, Resources, Styles and Layout
There's a whole new controls library to play with. We've seen the Window. We could also have used a Page if we were targeting a web application. There are also panels for layout, of which the aforementioned Grid is one implementation but here are more as layout is key to presentaional power, e.g. StackPanel, Canvas, DockPanel, ToolBar and Tab related controls. You also have the standard UI controls and a host more for you to explore, including data bound controls. Before long you'll want to include resources in your application, e.g. strings, images or a graphic element. This can be achieved by adding a resource to your application definition which is then avaiable for use by other objects. Styles are a sub-element of a resource definition and allow you to apply the resource to an object type or sub-set within an object type as opposed to having to apply the resource to each object explicitly.
Windows Workflow Foundation (WF)
Workflow refers to the steps involved in an application. WF enables developers to graphically build application workflow while keeping it logically distinct from the main application code and providing several of the common services required. Steps in an application workflow may be performed by a human or a computer and may need to integrate with an external application. The workflow files in WF are XML files written in a version of XAML, the same as that Used to describe WPF files. These files describe the actions to perform within the workflow and the relationship between those actions. You could use a text editor but VS enables developers to visually design the workflow, creating the XAML for you. A workflow is composed of a number of rule definitions with each definition including activities (work flow steps), conditions and expressions. Activities are run if conditions are met with expressions defining the tests of the conditions. Six main components make up any WF applicaton: 1. Host process – this is the executable that will host the workflow, typically a windows form, ASP.NET or windows service application. The workflow is hosted and runs within this process. 2. WF runtime services, responsible for o loading, scheduling and actual workflow execution o persistence – saving the state of the workflow as required o tracking – enabling (health) monitoring of the state of the workflow 3. Workflow runtime engine – responsible for executing each workflow instance 4. Workflow – the actual workflow which consists of one or more activities and may consist of workflow markup and/ or code. Mutipleinstances of a workflow may be active at any given time in an application. 5. Activity library – a collection of standard actions used to create workflows. 6. Custom activities – mostly achieved through attributes and inheritance. WF supports two main styles of workflows: sequential and state machine. Sequential workflows are the classic flowchart style of process (a series of steps with possible branching). State machine workflows are less linear. A good way to identify a candidate for a state machine workflow is determing whether the process is defined in terms of modes/ states. The standard WF activities can be divided into five major categories: 1. Communication with external code 2. Flow control 3. Action 4. Scope – group activities into a logical element, typically to participate in transactions 5. State – used exclusively in state machine workflows (one of the machines states) 3
WF integrates well into appplications including Windows Forms and ASp.NET applications. It provides a means to modularise the workflow from those applications, to graphically design the workflow in VS.NET for agreement with project stakeholders and the technology permits the workflow to be changed relatively easily without requiring changes to the core application.
Windows Communication Foundation (WCF)
This is really all about Service Oriented Architecture (SOA) - a non-proprietary, interoperable, distributed, message based architecture. Some principles of SOA are: • Entity boundaries are explicit with underlying functionaility accessed via the exposed interface. • Services are autonomous – hence published interfaces must remain unchanged • Services are based on contracts, schemas and policies – all services require a contract regarding what is required to consume items from the interface (usually done through WSDL document) Along with a contract, schemas are required to define the items passed as parameters or delivered through the service (using XSD schemas). Finally policies define any capabilities or requirements of the service. • Service compatiability that is based upon policy – enables services to decide policies, decided at ruyntime, that ar required to consume the service. These policies are usually expressed through WS-policy. WCF is a framework that works on SOA principles and makes it relatively simple to implement. It is also a means to build distributed applications in a Microsoft environment, though the consumers of the application certainly don’t need to be Microsoft clients. WCF allows you to build all kinds of distributed applications including 'traditional' Web Services so that your services support SOAP and will therefore be compatible with older .NET (and other) technologies. WCF is not just about pure SOAP over the wire - you can work with an Infoset, and create a binary representation of your SOAP message that can then be sent along with your choice of protocol. This is for those who are particularly concerned about performance and have traditionally turned to .NET remoting. WCF can also work with a message through its lifecycle meaning that WCF can deal with transactions like those of Enterprise Services. Along with distributed transactions, WCF can deal with the queuing of messages, and it allows for the intermittent connected nature that an application might have to deal with. WCF is all about messages but not just WebService like messages. For example, WCF can be used to communicate messages to components contained on the same machine on which the WCF service is running. Hence you can use WCF for communication between components contained in different processes on the same machine as well as with other components on another machine, whether that machine is a Microsoft OS based machine, or not. WCF also enables you to develop a service once and then expose that service via multiple endpoints (which can use entirely different protocols) via simple configuration changes.
WCF facilitates the utilisation of a framework of WS-* specifications which can be enabled to allow for defined ways of dealing with security, reliability and transactions (with incomplete notes): Security • WS-Security – supports credential exchange, message integrity and message confidentiality • WS-SecureConversation • WS-Trust Reliability • WS-ReliableMessaging Trasnactions • WS-AtomicTransaction • WS-Coordination Messaging • SOAP • WS-Addressing • MTOM – Message Transmission Optimization Mechanism, the replacement for DIME (Direct Internet Message Encapsulation) as ameans to transmit binary objects along with a SOAP message Metadata – allows definition of your interface • WSDL • WS-Policy – provides consumers with a specification of what is required to consume the service • WS-MetadataExchange These use the SOAP header enabling messages to be self contained and not rely on the transport protocol for anything but transmission of the message itself. WCF can therefore make use of these specifications if the developer wishes. If currently working in a .NET 2.0 environment you need to install .NET 3 and to build WCF services directly in VS2005 you need to install the VS2005 extensions for .NET 3 (WCF and WPF). If you are using a VS2008 Beta, or indeed the full product by the time you read this, you’ll be ready to go already. You’ll then be able to add a WCF project.
WCF Service Constituents
The service 2.One or more endpoints 3.The host environment A service is a .NET class which contains methods exposed through the WCF service. A service can have one or more endpoints which allow a client to communicate with the service. Endpoints are made up of 3 parts: A – address (where), B – binding (how), C – contract (what). The host envionment constitutes an application domain and process of any form suggested by requirements (console, windows forms, WPF, windows services, IIS). To create a WCF service you need to • create a service contract (the class with the methods you want to expose), and a • data contract (a class that specifies the structure you want to expose from the interface) To use the service you need to create the WSDL document that will be used by the client, then create the client itself.
I hope this whistlestop tour of 3 of the 4 main new elments in .NET 3.0 has been useful. Hopefully there will be more practial articles to follow on DotNetJohn to build on this theoretical information.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.