page 1 of 28 · the global acceptance of web services, which includes standard protocols for...

28
Page 1 of 28 What Is Windows Communication Foundation? The global acceptance of Web services, which includes standard protocols for application-to- application communication, has changed software development. For example, the functions that Web services now provide include security, distributed transaction coordination, and reliable communication. The benefits of the changes in Web services should be reflected in the tools and technologies that developers use. Windows Communication Foundation (WCF) is designed to offer a manageable approach to distributed computing, broad interoperability, and direct support for service orientation. WCF simplifies development of connected applications through a new service-oriented programming model. WCF supports many styles of distributed application development by providing a layered architecture. At its base, the WCF channel architecture provides asynchronous, untyped message-passing primitives. Built on top of this base are protocol facilities for secure, reliable, transacted data exchange and broad choice of transport and encoding options. The typed programming model (called the service model) is designed to ease the development of distributed applications and to provide developers with expertise in ASP.NET Web services, .NET Framework remoting, and Enterprise Services, and who are coming to WCF with a familiar development experience. The service model features a straightforward mapping of Web services concepts to those of the .NET Framework common language runtime (CLR), including flexible and extensible mapping of messages to service implementations in languages such as Visual C# or Visual Basic. It includes serialization facilities that enable loose coupling and versioning, and it provides integration and interoperability with existing .NET Framework distributed systems technologies such as Message Queuing (MSMQ), COM+, ASP.NET Web services, Web Services Enhancements (WSE), and a number of other functions. Problem Example The following example illustrates some of the problems that WCF addresses. A car rental company decides to create a new application for reserving cars. The creators of this rental car reservation application know that the business logic it implements must be accessible by other software running both inside and outside their company. Accordingly, they decide to build it in a service-oriented style, with the application’s logic exposed to other software through a well-defined set of services. To implement these services, and thus communicate with other software, the new application will use WCF. Copy Rights 2009. Powered by Wits Square Technologies.

Upload: others

Post on 21-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 1 of 28

What Is Windows Communication Foundation?The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example, the functions that Web services now provide include security, distributed transaction coordination, and reliable communication. The benefits of the changes in Web services should be reflected in the tools and technologies that developers use. Windows Communication Foundation (WCF) is designed to offer a manageable approach to distributed computing, broad interoperability, and direct support for service orientation.

WCF simplifies development of connected applications through a new service-oriented programming model. WCF supports many styles of distributed application development by providing a layered architecture. At its base, the WCF channel architecture provides asynchronous, untyped message-passing primitives. Built on top of this base are protocol facilities for secure, reliable, transacted data exchange and broad choice of transport and encoding options.

The typed programming model (called the service model) is designed to ease the development of distributed applications and to provide developers with expertise in ASP.NET Web services, .NET Framework remoting, and Enterprise Services, and who are coming to WCF with a familiar development experience. The service model features a straightforward mapping of Web services concepts to those of the .NET Framework common language runtime (CLR), including flexible and extensible mapping of messages to service implementations in languages such as Visual C# or Visual Basic. It includes serialization facilities that enable loose coupling and versioning, and it provides integration and interoperability with existing .NET Framework distributed systems technologies such as Message Queuing (MSMQ), COM+, ASP.NET Web services, Web Services Enhancements (WSE), and a number of other functions.

Problem Example

The following example illustrates some of the problems that WCF addresses. A car rental company decides to create a new application for reserving cars. The creators of this rental car reservation application know that the business logic it implements must be accessible by other software running both inside and outside their company. Accordingly, they decide to build it in a service-oriented style, with the application’s logic exposed to other software through a well-defined set of services. To implement these services, and thus communicate with other software, the new application will use WCF.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 2: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 2 of 28

Over its lifetime, the rental car reservation application will likely be accessed by a range of other applications. When it is designed, however, the architects of the rental car reservation application know that its business logic will be accessed, as shown in the preceding figure, by three other kinds of software:

• A call center client application running on the Windows desktops that are used by

employees in the organization’s call center. Created specifically for the new

reservations system, this application will also be built using the Microsoft .NET

Framework and WCF. This application is not truly distinct from the new rental car

reservation application, because its only purpose is to act as a client for the new

system. From a service-oriented perspective, it is just another client for the

reservation system’s business logic.

• An existing reservation application built on a J2EE server running on a non-Windows

system. Due to a recent merger with another car rental firm, this existing system

must be able to access the new application’s logic to provide customers of the

merged firms with a unified experience.

• Partner applications running on a variety of platforms, each located within a company

that has a business arrangement with the car rental firm. Partners might include

travel agencies, airlines, and others that have a business requirement to make car

rental reservations.

The diverse communication requirements for the new rental car reservation application are not simple. For interactions with the call center client application, for instance, performance is important, while interoperability is straightforward, because both are built on the .NET Framework. For communication with the existing J2EE-based reservation application and with the diverse partner applications, however, interoperability becomes the highest goal. The security requirements are also quite different, varying across local Windows-based applications, a J2EE-based application running on another operating system, and a variety of

Copy Rights 2009. Powered by Wits Square Technologies.

Page 3: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 3 of 28

partner applications coming in across the Internet. Even transactional requirements might vary, with only the internal applications being allowed to make transactional requests. How can these diverse business and technical requirements be met without exposing the creators of the new application to unmanageable complexity?

WCF is designed for this diverse but realistic scenario and is the default technology for Windows applications that expose and access services. This topic provides an introduction to WCF, examining what it provides and showing how it is used. Throughout this introduction, the scenario just described will serve as an example. The goal is to make clear what WCF is, show what problems it solves, and illustrate how it solves those problems.

Addressing the Problem

The foundation for new Windows-based applications is the .NET Framework. Accordingly, WCF is implemented primarily as a set of classes on top of the .NET Framework CLR. Because it extends their familiar environment, WCF enables developers who create object-oriented applications using the .NET Framework today to also build service-oriented applications in a familiar way.

The figure shows a view of a WCF client and service. The two interact using SOAP, the WCF native message representation, so even though the figure shows both parties built on WCF, this is not required. WCF is built on .NET Framework 2.0.

As the scenario described earlier suggests, WCF addresses a range of challenges for communicating applications. Three things stand out, however, as the most important aspects of WCF:

• Unification of existing .NET Framework communication technologies.

• Support for cross-vendor interoperability, including reliability, security, and

transactions.

• Explicit service orientation.

Unification of Microsoft Distributed Computing TechnologiesIn the absence of WCF, the development team that implements the rental car application would need to choose the right distributed technology from the multiple choices offered by the .NET Framework. Yet given the diverse requirements of this application, no single technology would fit the requirements. Instead, the application would probably use multiple existing .NET Framework technologies, such as the following:

• ASP.NET Web services (ASMX). An option for communicating with the J2EE-based

existing reservation application and with the partner applications across the Internet.

Given that basic Web services are supported today on most platforms, this was the

most direct way to achieve cross-vendor interoperability before the release of WCF.

• .NET Framework remoting. An option for communication with the call center

application, because both are built on the .NET Framework. Remoting is designed

Copy Rights 2009. Powered by Wits Square Technologies.

Page 4: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 4 of 28

expressly for tightly coupled .NET-to-.NET communication, so it offers a seamless and

straightforward development experience for applications in the local network.

• Enterprise Services. Used by the rental car reservation application for managing

object lifetimes and defining distributed transactions. These functions could be useful

in communicating and integrating with any of the other applications in this scenario,

but Enterprise Services supports only a limited set of communication options.

• WSE. Could be used along with ASMX to communicate with the J2EE-based

reservation application and with the partner applications. Because it implements

more recently defined Web services agreements, known collectively as the WS-*

specifications, WSE allows for more flexible Web services security, as long as all

applications involved support compatible versions of these new specifications.

• Microsoft Message Queuing (MSMQ). Used to communicate with Windows-based

partner applications that require guaranteed data delivery as well as decoupling of

workloads and application lifetimes. The durable messaging that Message Queuing

provides is typically the best solution for intermittently connected applications.

Built on .NET Framework, the rental car reservation application must use more than one of these communication technologies to meet its requirements. Although this is technically possible, the resulting application would be complex to implement and challenging to maintain.

With WCF, the solution is much easier to implement. As the figure shows, WCF can be used for all the situations previously described. Accordingly, the rental car reservation application can use this single technology for all of its application-to-application communication. The following shows how WCF addresses each of these requirements:

• Because WCF can communicate using Web services, interoperability with other

platforms that also support SOAP, such as the leading J2EE-based application

servers, is straightforward.

• You can also configure and extend WCF to communicate with Web services using

messages not based on SOAP, for example, simple XML formats like RSS.

• Performance is of paramount concern for most businesses. WCF is developed with

the goal of being one of the fastest distributed application platform developed by

Microsoft. For a high-level performance comparison between WCF and other

Microsoft .NET distributed communication technologies, see

http://go.microsoft.com/fwlink/?LinkId=94274.

• To allow optimal performance when both parties in a communication are built on

WCF, the wire encoding used in this case is an optimized binary version of an XML

Information Set. Messages still conform to the data structure of a SOAP message, but

their encoding uses a binary representation of that data structure rather than the

Copy Rights 2009. Powered by Wits Square Technologies.

Page 5: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 5 of 28

standard angle-brackets-and-text format of the XML 1.0 text encoding. Using this

option makes sense for communicating with the call center client application, because

it is also built on WCF, and performance is an important concern.

• Managing object lifetimes, defining distributed transactions, and other aspects of

Enterprise Services are now provided by WCF. They are available to any WCF-based

application, which means that the rental car reservation application can use them

with any of the other applications it communicates with.

• Because it supports a large set of the WS-* specifications, WCF helps provide

reliability, security, and transactions when communicating with any platform that also

supports these specifications.

• The WCF option for queued messaging, built on Message Queuing, allows

applications to use persistent queuing without using another set of application

programming interfaces.

The result of this unification is greater functionality and significantly reduced complexity.

Interoperability with Applications Built on Other Technologies

While WCF introduces a new development environment for distributed applications, it is designed to interoperate well with the non-WCF applications. There are two important aspects to WCF interoperability: interoperability with other platforms, and interoperability with the Microsoft technologies that preceded WCF. The following section describes both.

Interoperability with Other Web Services PlatformsEnterprises today typically have systems and applications that they purchased from a range of suppliers. In the rental car application, for instance, communication is required with various other software applications written in various languages and running on various operating systems.

Because WCF’s fundamental communication mechanism is SOAP-based Web services, WCF-based applications can communicate with other software running in a variety of contexts. An application built on WCF can interact with all of the following:

• WCF-based applications running in a different process on the same Windows

machine.

• WCF-based applications running on another Windows machine.

• Applications built on other technologies, such as J2EE application servers, that

support standard Web services. These applications can be running on Windows

machines or on machines running other operating systems.

To allow more than just basic communication, WCF implements Web services technologies defined by the WS-* specifications. All of these specifications were originally defined by Microsoft, IBM, and other vendors working together. As the specifications become stable, ownership often passes to standards bodies, such as the World Wide Web Consortium (W3C) or the Organization for the Advancement of Structured Information Standards (OASIS). These

Copy Rights 2009. Powered by Wits Square Technologies.

Page 6: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 6 of 28

specifications address several areas, including basic messaging, security, reliability, transactions, and working with a service’s metadata. For more information, see Interoperability and Integration with Windows Communication Foundation. For more information about advanced Web services specifications, see http://go.microsoft.com/fwlink/?LinkId=86603.

Grouped by function, those specifications cover:

• Messaging: SOAP is the foundation for Web services and defines a basic envelope

that contains header and a body sections. WS-Addressing defines additions to the

SOAP header for addressing SOAP messages, which frees SOAP from relying on the

underlying transport protocol, such as HTTP, to carry addressing information.

Message Transmission Optimization Mechanism (MTOM) defines an optimized

transmission format for SOAP messages with large binary data contents based on the

XML-binary Optimized Packaging (XOP) specification.

• Metadata: The Web Services Description Language (WSDL) defines a standard

language for specifying services and various aspects of how those services can be

used. WS-Policy allows specification of more dynamic aspects of a service’s behavior

that cannot be expressed in WSDL, such as a preferred security option. WS-

MetadataExchange allows a client to directly request descriptive information about a

service, such as its WSDL and its policies, using SOAP.

• Security: WS-Security, WS-SecureConversation, WS-Trust, and WS-Federation all

define additions to SOAP messages for providing authentication, data integrity, data

privacy, and other security features.

• Reliability: WS-Reliable Messaging defines additions to the SOAP header that allow

reliable end-to-end communication, even when one or more Web services

intermediaries must be traversed.

• Transactions: Built on WS-Coordination, WS-Atomic Transaction allows coordinating

two-phase commit transactions in the context of Web services conversations.

The rental car reservation application would likely use several of these more advanced technologies. For example, WS-Addressing is essential whenever SOAP is used over a transport mechanism other than HTTP, which might be the case for communication with the .NET Framework-based call center client application. WCF relies on WS-Policy and WS-Metadata Exchange to discover whether the system it is communicating with is also using WCF and for other things. Reliable communication is essential for most situations, so it is likely that WS-Reliable Messaging would be used to interact with many of the other applications in this scenario. Similarly, you might also use WS-Security and the related specifications for securing the communication with one or more of the applications, because all would require some kind of protection against unauthorized access or message modification and interception. For the applications that require transaction integration with the rental car reservation system, WS-Atomic Transaction would be essential. Finally, MTOM could be used whenever an optimized wire format for binary data is necessary (for instance for pictures of fleet examples), and both sides of the communication supported this option.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 7: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 7 of 28

The key point is that WCF implements interoperable Web services complete with cross-platform security, reliability, transactions, and other services. To provide maximum throughput, WCF-to-WCF communication can be significantly optimized, but all other communication uses standard Web services protocols. In fact, it is possible for a single application to expose its services to both kinds of clients.

Interoperability with Microsoft TechnologiesMany Microsoft customers have made significant investments in the .NET Framework technologies that WCF includes. Protecting those investments was a fundamental goal of WCF’s designers. Installing WCF does not break existing technology, so there is no requirement that organizations change existing applications to use it. A clear upgrade path is provided, however, and wherever possible, WCF interoperates with those earlier technologies.

For example, both WCF and ASMX use SOAP, so WCF-based applications can directly interoperate with those built on ASMX. Existing Enterprise Services applications can also be wrapped with WCF interfaces, allowing them to interoperate with applications built on WCF. And because persistent queuing in WCF relies on MSMQ, WCF-based applications can interoperate directly with non-WCF-based applications built using native MSMQ interfaces. In the rental car reservations application, software built using any of these earlier technologies could directly connect to and use the new system’s WCF-based services.

Interoperability is not always possible, however. For example, even though WSE 1.0 and WSE 2.0 implement some of the same WS-* specifications as WCF, these earlier technologies implement earlier versions of the specifications. Version 3.0 of WSE does allow interoperability with WCF, but earlier versions do not. For more information about interoperability, see Migrating WSE 3.0 Web Services to WCF.

Interoperability with Other XML Protocols

The future of the Internet is not predictable and the technologies used today may evolve or be replaced. Today, a popular trend in building Web-centric applications (called by many "Web 2.0"), is an application model based on communication using only simple XML formats that are not SOAP-based and exclusively rely on HTTP as a transport and as an application protocol. For example, the Representational State Transfer (REST) architectural style has no notion of user-defined operations for dealing with data. Instead, application state is associated with HTTP URLs and HTTP methods (such as PUT, POST, DELETE, and GET). This approach is in contrast to the creation of user-defined procedures or functions that most developers are familiar with in an enterprise environment. However, the REST approach is of value in scenarios where services must function as the back end of Web 2.0 applications.

REST is just one example of an evolving Web 2.0 technology. In this environment of experimental programming models and ongoing reinterpretation and refinement of standards, flexibility is required to cope with unforeseeable changes. WCF is flexible. For example, while WCF uses SOAP as an underlying structure, it is not bound to using SOAP for wire communication. In fact, WCF can be configured to process "plain" XML data that is not wrapped in a SOAP envelope. WCF can also be extended to support specific XML formats, such as ATOM (a popular RSS standard), and even non-XML formats, such as JavaScript Object Notation (JSON). This flexibility ensures that code written today will be valid in the future, even if protocols change or are replaced. Therefore, WCF was designed for the present and the future.

Fundamental Windows Communication Foundation ConceptsThis document provides a high-level view of the Windows Communication Foundation (WCF) architecture. It is intended to explain key concepts and how they fit together. For a tutorial on creating the simplest version of a WCF service and client, see Getting Started Tutorial. To learn WCF programming, see Basic WCF Programming.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 8: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 8 of 28

WCF Fundamentals

Windows Communication Foundation (WCF) is a runtime and a set of APIs for creating systems that send messages between services and clients. The same infrastructure and APIs are used to create applications that communicate with other applications on the same computer system or on a system that resides in another company and is accessed over the Internet.

Messaging and EndpointsWCF is based on the notion of message-based communication, and anything that can be modeled as a message (for example, an HTTP request or an MSMQ message) can be represented in a uniform way in the programming model. This enables a unified API across different transport mechanisms.

The model distinguishes between clients, which are applications that initiate communication, and services, which are applications that wait for clients to communicate with them and respond to that communication. A single application can act as both a client and a service.

Messages are sent between endpoints. Endpoints are places where messages are sent or received (or both), and they define all the information required for the message exchange. A service exposes one or more application endpoints (as well as zero or more infrastructure endpoints), and the client generates an endpoint that is compatible with one of the service's endpoints.

An endpoint describes in a standard-based way where messages should be sent, how they should be sent, and what the messages should look like. A service can expose this information as metadata that clients can process to generate appropriate WCF clients and communication stacks.

Communication ProtocolsOne required element of the communication stack is the transport protocol. Messages can be sent over intranets and the Internet using common transports, such as HTTP and TCP. Other transports are included that support communication with Microsoft Message Queuing (MSMQ) applications and nodes on a Peer Networking mesh. More transport mechanisms can be added using the built-in extension points of WCF.

Another required element in the communication stack is the encoding that specifies how any given message is formatted. WCF provides the following encodings:

• Text encoding, an interoperable encoding.

• Message Transmission Optimization Mechanism (MTOM) encoding, which is an

interoperable way for efficiently sending unstructured binary data to and from a

service.

• Binary encoding for efficient transfer.

More encoding mechanisms (for example, a compression encoding) can be added using the built-in extension points of WCF.

Message PatternsWCF supports several messaging patterns, including request-reply, one-way, and duplex communication. Different transports support different messaging patterns, and thus affect the types of interactions that they support. The WCF APIs and runtime also help you to send messages securely and reliably.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 9: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 9 of 28

WCF Terms

Other concepts and terms used in the WCF documentation include the following.

message A message is a self-contained unit of data that may consist of several parts, including a body and headers.

service A service is a construct that exposes one or more endpoints, with each endpoint exposing one or more service operations.

endpoint An endpoint is a construct at which messages are sent or received (or both). It comprises a location (an address) that defines where messages can be sent, a specification of the communication mechanism (a binding) that described how messages should be sent, and a definition for a set of messages that can be sent or received (or both) at that location (a service contract) that describes what message can be sent. An WCF service is exposed to the world as a collection of endpoints.

application endpoint An endpoint exposed by the application and that corresponds to a service contract implemented by the application.

infrastructure endpoint An endpoint that is exposed by the infrastructure to facilitate functionality that is needed or provided by the service that does not relate to a service contract. For example, a service might have an infrastructure endpoint that provides metadata information.

address An address specifies the location where messages are received. It is specified as a Uniform Resource Identifier (URI). The URI schema part names the transport mechanism to use to reach the address, such as HTTP and TCP. The hierarchical part of the URI contains a unique location whose format is dependent on the transport mechanism. The endpoint address enables you to create unique endpoint addresses for each endpoint in a service, or under certain conditions share an address across endpoints. The following example shows an address using the HTTPS protocol with a non-default port:

Copy Code HTTPS://cohowinery:8005/ServiceModelSamples/CalculatorService

binding A binding defines how an endpoint communicates to the world. It is constructed of a set of components called binding elements that "stack" one on top of the other to create the communication infrastructure. At the very least, a binding defines the transport (such as HTTP or TCP) and the encoding being used (such as text or binary). A binding can contain binding elements that specify details like the security mechanisms used to secure messages, or the message pattern used by an endpoint. For more information, see Configuring Windows Communication Foundation Services.

binding element A binding element represents a particular piece of the binding, such as a transport, an encoding, an implementation of an infrastructure-level protocol (such as WS-ReliableMessaging), or any other component of the communication stack.

behaviors A behavior is a component that controls various run-time aspects of a service, an endpoint, a particular operation, or a client. Behaviors are grouped according to scope: common behaviors affect all endpoints globally, service behaviors affect only service-related aspects, endpoint behaviors affect only endpoint-related properties, and operation-level behaviors affect particular operations. For example, one service behavior is throttling, which specifies how a service reacts when an excess of

Copy Rights 2009. Powered by Wits Square Technologies.

Page 10: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 10 of 28

messages threaten to overwhelm its handling capabilities. An endpoint behavior, on the other hand, controls only aspects relevant to endpoints, such as how and where to find a security credential.

system-provided bindings WCF includes a number of system-provided bindings. These are collections of binding elements that are optimized for specific scenarios. For example, the WSHttpBinding is designed for interoperability with services that implement various WS-* specifications. These predefined bindings save time by presenting only those options that can be correctly applied to the specific scenario. If a predefined binding does not meet your requirements, you can create your own custom binding.

configuration versus coding Control of an application can be done either through coding, through configuration, or through a combination of both. Configuration has the advantage of allowing someone other than the developer (for example, a network administrator) to set client and service parameters after the code is written and without having to recompile. Configuration not only enables you to set values like endpoint addresses, but also allows further control by enabling you to add endpoints, bindings, and behaviors. Coding allows the developer to retain strict control over all components of the service or client, and any settings done through the configuration can be inspected and if needed overridden by the code.

service operation A service operation is a procedure defined in a service's code that implements the functionality for an operation. This operation is exposed to clients as methods on a WCF client. The method may return a value, and may take an optional number of arguments, or take no arguments, and return no response. For example, an operation that functions as a simple "Hello" can be used as a notification of a client's presence and to begin a series of operations.

service contract The service contract ties together multiple related operations into a single functional unit. The contract can define service-level settings, such as the namespace of the service, a corresponding callback contract, and other such settings. In most cases, the contract is defined by creating an interface in the programming language of your choice and applying the ServiceContractAttribute attribute to the interface. The actual service code results by implementing the interface.

operation contract An operation contract defines the parameters and return type of an operation. When creating an interface that defines the service contract, you signify an operation contract by applying the OperationContractAttribute attribute to each method definition that is part of the contract. The operations can be modeled as taking a single message and returning a single message, or as taking a set of types and returning a type. In the latter case, the system will determine the format for the messages that need to be exchanged for that operation.

message contract A message contract describes the format of a message. For example, it declares whether message elements should go in headers versus the body, what level of security should be applied to what elements of the message, and so on.

fault contract A fault contract can be associated with a service operation to denote errors that can be returned to the caller. An operation can have zero or more faults associated with it. These errors are SOAP faults that are modeled as exceptions in the programming model.

data contract The data types a service uses must be described in metadata to enable others to interoperate with the service. The descriptions of the data types are known as the data contract, and the types can be used in any part of a message, for example, as parameters or return types. If the service is using only simple types, there is no need to explicitly use data contracts.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 11: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 11 of 28

hosting A service must be hosted in some process. A host is an application that controls the lifetime of the service. Services can be self-hosted or managed by an existing hosting process.

self-hosted service A self-hosted service is one that runs within a process application that the developer created. The developer controls its lifetime, sets the properties of the service, opens the service (which sets it into a listening mode), and closes the service.

hosting process A hosting process is an application that is designed to host services. These include Internet Information Services (IIS), Windows Activation Services (WAS), and Windows Services. In these hosted scenarios, the host controls the lifetime of the service. For example, using IIS you can set up a virtual directory that contains the service assembly and configuration file. When a message is received, IIS starts the service and controls its lifetime.

instancing A service has an instancing model. There are three instancing models: "single," in which a single CLR object services all the clients; "per call," in which a new CLR object is created to handle each client call; and "per session," in which a set of CLR objects are created, one for each separate session. The choice of an instancing model depends on the application requirements and the expected usage pattern of the service.

client application A client application is a program that exchanges messages with one or more endpoints. The client application begins by creating an instance of a WCF client and calling methods of the WCF client. It is important to note that a single application can be both a client and a service.

channel A channel is a concrete implementation of a binding element. The binding represents the configuration, and the channel is the implementation associated with that configuration. Therefore, there is a channel associated with each binding element. Channels stack on top of each other to create the concrete implementation of the binding: the channel stack.

WCF client A WCF client is a client-application construct that exposes the service operations as methods (in the .NET Framework programming language of your choice, such as Visual Basic or Visual C#). Any application can host a WCF client, including an application that hosts a service. Therefore, it is possible to create a service that includes WCF clients of other services. A WCF client can be automatically generated by using the ServiceModel Metadata Utility Tool (Svcutil.exe) and pointing it at a running service that publishes metadata.

metadata The metadata of a service describes the characteristics of the service that an external entity needs to understand to communicate with the service. Metadata can be consumed by the ServiceModel Metadata Utility Tool (Svcutil.exe) to generate a WCF client and accompanying configuration that a client application can use to interact with the service. The metadata exposed by the service includes XML schema documents, which define the data contract of the service, and WSDL documents, which describe the methods of the service. When enabled, metadata for the service is automatically generated by WCF by inspecting the service and its endpoints. To publish metadata from a service, you must explicitly enable the metadata behavior.

security Security in WCF includes confidentiality (encryption of messages to prevent eavesdropping), integrity (the means for detection of tampering with the message), authentication (the means for validation of servers and clients), and authorization

Copy Rights 2009. Powered by Wits Square Technologies.

Page 12: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 12 of 28

(the control of access to resources). These functions are provided by either leveraging existing security mechanisms, such as TLS over HTTP (also known as HTTPS), or by implementing one or more of the various WS-* security specifications.

transport security mode Security can be provided by one of three modes: transport mode, message security mode, and transport with message credential mode. The transport security mode specifies that confidentiality, integrity, and authentication are provided by the transport layer mechanisms (such as HTTPS). When using a transport like HTTPS, this mode has the advantage of being efficient in its performance, and well understood because of its prevalence on the Internet. The disadvantage is that this kind of security is applied separately on each hop in the communication path, making the communication susceptible to a "man in the middle" attack.

message security mode Message security mode specifies that security is provided by implementing one or more of the security specifications, such as the specification named "Web Services Security: SOAP Message Security" (available at http://go.microsoft.com/fwlink/?LinkId=94684). Each message contains the necessary mechanisms to provide security during its transit, and to enable the receivers to detect tampering and to decrypt the messages. In this sense, the security is encapsulated within every message, providing end-to-end security across multiple hops. Because security information becomes part of the message, it is also possible to include multiple kinds of credentials with the message (these are referred to as claims). This approach also has the advantage of enabling the message to travel securely over any transport, including multiple transports between its origin and destination. The disadvantage of this approach is the complexity of the cryptographic mechanisms employed, resulting in performance implications.

transport with message credential security mode This mode uses the transport layer to provide confidentiality, authentication, and integrity of the messages, while each of the messages can contain multiple credentials (claims) required by the receivers of the message.

WS-* Shorthand for the growing set of Web Service (WS) specifications, such as WS-Security, WS-ReliableMessaging, and so on, that are implemented in WCF.

Windows Communication Foundation ArchitectureThe following graphic illustrates the major layers of the Windows Communication Foundation (WCF) architecture.

WCF Architecture

Copy Rights 2009. Powered by Wits Square Technologies.

Page 13: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 13 of 28

Contracts and DescriptionsContracts define various aspects of the message system. The data contract describes every parameter that makes up every message that a service can create or consume. The message parameters are defined by XML Schema definition language (XSD) documents, enabling any system that understands XML to process the documents. The message contract defines specific message parts using SOAP protocols, and allows finer-grained control over parts of the message, when interoperability demands such precision. The service contract specifies the actual method signatures of the service, and is distributed as an interface in one of the supported programming languages, such as Visual Basic or Visual C#.

Policies and bindings stipulate the conditions required to communicate with a service. For example, the binding must (at a minimum) specify the transport used (for example, HTTP or TCP), and an encoding. Policies include security requirements and other conditions that must be met to communicate with a service.

Service RuntimeThe service runtime layer contains the behaviors that occur only during the actual operation of the service, that is, the runtime behaviors of the service. Throttling controls how many messages are processed, which can be varied if the demand for the service grows to a preset limit. An error behavior specifies what occurs when an internal error occurs on the service, for example, by controlling what information is communicated to the client. (Too much information can give a malicious user an advantage in mounting an attack.) Metadata behavior governs how and whether metadata is made available to the outside world. Instance behavior specifies how many instances of the service can be run (for example, a singleton specifies only one instance to process all messages). Transaction behavior enables the rollback of transacted operations if a failure occurs. Dispatch behavior is the control of how a message is processed by the WCF infrastructure.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 14: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 14 of 28

Extensibility enables customization of runtime processes. For example, message inspection is the facility to inspect parts of a message, and parameter filtering enables preset actions to occur based on filters acting on message headers.

MessagingThe messaging layer is composed of channels. A channel is a component that processes a message in some way, for example, by authenticating a message. A set of channels is also known as a channel stack. Channels operate on messages and message headers. This is different from the service runtime layer, which is primarily concerned about processing the contents of message bodies.

There are two types of channels: transport channels and protocol channels.

Transport channels read and write messages from the network (or some other communication point with the outside world). Some transports use an encoder to convert messages (which are represented as XML Infosets) to and from the byte stream representation used by the network. Examples of transports are HTTP, named pipes, TCP, and MSMQ. Examples of encodings are XML and optimized binary.

Protocol channels implement message processing protocols, often by reading or writing additional headers to the message. Examples of such protocols include WS-Security and WS-Reliability.

The messaging layer illustrates the possible formats and exchange patterns of the data. WS-Security is an implementation of the WS-Security specification enabling security at the message layer. The WS-Reliable Messaging channel enables the guarantee of message delivery. The encoders present a variety of encodings that can be used to suit the needs of the message. The HTTP channel specifies that the HyperText Transport Protocol is used for message delivery. The TCP channel similarly specifies the TCP protocol. The Transaction Flow channel governs transacted message patterns. The Named Pipe channel enables interprocess communication. The MSMQ channel enables interoperation with MSMQ applications.

Hosting and ActivationIn its final form, a service is a program. Like other programs, a service must be run in an executable. This is known as a self-hosted service.

Services can also be hosted, or run in an executable managed by an external agent, such as IIS or Windows Activation Service (WAS). WAS enables WCF applications to be activated automatically when deployed on a computer running WAS. Services can also be manually run as executables (.exe files). A service can also be run automatically as a Windows service. COM+ components can also be hosted as WCF services.

WPF Designer OverviewThis topic describes the Windows Presentation Foundation (WPF) Designer for Visual Studio. WPF is the user interface technology for Windows Vista and is distinct from earlier view technologies, such as Windows Forms.

The WPF Designer provides visual design support similar to the Windows Forms Designer. You can build user interfaces for your applications by dragging controls from the Toolbox and setting properties in the Properties window. You can also edit XAML directly in the XAML editor.

WPF Designer Windows The WPF Designer has several windows for displaying and editing XAML documents. The following illustration shows some of the windows in the WPF Designer.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 15: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 15 of 28

Design ViewDesign view provides a visual design surface for building your WPF controls and applications. It shows a rendered representation of the XAML currently in XAML view.

You can place controls on the design surface by dragging them from the Toolbox, and you can position controls by dragging. Several design aids help you place controls exactly where you want them. When you change controls on the design surface, XAML view updates to reflect your changes. For more information, see How To: Add Controls to a WPF Window and How to: Select and Move Elements on the Design Surface.

XAML ViewXAML view provides a complete editing experience for XAML documents, that includes IntelliSense, auto-formatting, syntax highlighting, and tag navigation. When you edit XAML, Design view updates to reflect your changes.

For more information, see Walkthrough: Editing XAML in the WPF Designer.

Properties WindowYou use the Properties window to set property values on controls in Design view.

Access the Properties window by opening the View menu and selecting Properties Window, or by pressing CTRL+W, P or F4. You can also right-click a control in Design view, and select Properties on the shortcut menu. The Properties window displays a thumbnail preview of the currently selected control.

To search for a property, start typing the name of the property in the Search box at the top of the Properties window. The Properties window shows the properties that match your search as you type. Click Clear to remove the search and display all the selected object's properties.

Starting in Visual Studio 2008 Service Pack 1, you can sort properties alphabetically or by category. To sort properties alphabetically, click the Alphabetical button at the top of the Properties window. To sort properties by category, click the Categorized button at the top of the Properties window.

Document Outline WindowThe Document Outline window provides a hierarchical view of a XAML document. You can use the Document Outline window to preview, select, or delete XAML elements. Access the Document Outline window by opening the View menu, pointing to Other Windows, and selecting Document Outline, or by pressing CTRL+ALT+T. For more information, see Navigating the Element Hierarchy of a WPF Document.

Toolbox

Copy Rights 2009. Powered by Wits Square Technologies.

Page 16: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 16 of 28

The Toolbox holds the controls which you can drag onto the design surface. Access the Toolbox window by opening the View menu and selecting Toolbox, or by pressing CTRL+ALT+X.

Design View Features Design view provides many features for arranging controls in your WPF application's window or page. Some of the Design view features are shown in the following illustration.

Zoom ControlUse the Zoom control to control the size of the design surface. You can zoom from 10% to 20x.

Fit In ViewUse the Fit in view button to size the design surface to the available screen in Design view. This is useful if you have zoomed very far in or out.

Grid RailsUse the grid rails to manage rows and columns in a Grid control. You can create and delete columns and rows, and you can adjust their relative widths and heights. For more information, see How to: Add Rows and Columns to a Grid.

GridlinesUse gridlines to control the width and height of a Grid's columns and rows. You can add a new column or row by clicking in the rails above and to the left of the Grid. For more information, see How to: Add Rows and Columns to a Grid.

Gridline IndicatorsA gridline indicator appears as a triangle in the grid rail. When you drag a gridline indicator or the gridline itself, the widths or heights of adjacent columns or rows update as you move the mouse. For more information, see How to: Add Rows and Columns to a Grid.

Move Handle

Copy Rights 2009. Powered by Wits Square Technologies.

Page 17: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 17 of 28

A move handle appears in the upper-left of a selected panel control. Click the move handle and drag the control to the desired position on the design surface. For more information, see How to: Select and Move Elements on the Design Surface.

Resize HandlesResize handles appear on selected controls. Click and drag a resize handle to change the size of the selection. When you resize a control, width and height values typically appear to help exactly size the control.

Margin LinesMargins represent the amount of fixed space between the edge of a control and the edge of its container. Set the margins of a control by clicking its margin lines. For more information, see How to: Set Margins for a Control in the WPF Designer.

Margin StubsA margin stub appears on a selected control when its margin in set to 0. Click the margin stub to set a margin distance to the corresponding edge of the container. For more information, see How to: Set Margins for a Control in the WPF Designer.

SnaplinesUse snaplines to align controls relative to each other. If snaplines are enabled, when you drag a control relative to other controls, snaplines appear when edges and the text of some controls are aligned horizontally or vertically. For more information, see How to: Align to Both Text Baselines and Margins.

XAML View Features The Extensible Application Markup Language (XAML) provides a declarative, XML-based vocabulary for specifying an application's user interface. The WPF Designer provides a unique split view, which provides a XAML view and a synchronized Design view of your application's rendered XAML markup. Some of the XAML features are shown in the following illustration.

For more information, see Split View: Viewing the WPF Design Surface and XAML at the Same Time.

Split View BarUse the split view bar to control the relative sizes of Design view and XAML view. You can control whether the split view is horizontal or vertical, and you can collapse either view. For more information, see Split View: Viewing the WPF Design Surface and XAML at the Same Time.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 18: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 18 of 28

Tag NavigatorYou can move to any parent tag of the currently selected tag in XAML view by using the tag navigator. When you hover over a tag in the tag navigator, a thumbnail preview is displayed for that element. Walkthrough: Editing XAML in the WPF Designer.

Building Rich, Interactive User Interfaces In WPF, the Window and Page classes are visual surfaces on which you display information to the user. You ordinarily build WPF applications by adding controls to a Window and developing responses to user actions, such as mouse clicks or key presses. A control is a discrete user interface (UI) element that displays data or accepts data input. When a user does something to your Window or one of its controls, the action generates an event. Your application reacts to these events and processes them when they occur. For more information, see How to: Create a Simple Event Handler.

WPF contains a variety of controls that you can add to a window: controls that display text boxes, buttons, drop-down lists, radio buttons, and even Web pages. For a list of all the controls you can use in a window, see Control Library. If an existing control does not meet your needs, WPF also supports creating your own custom controls by using the UserControl and Control classes.

With the drag-and-drop WPF Designer, you can easily create WPF applications. Just select the controls with your pointer and add them where you want in the window. The designer provides tools, such as snaplines and continuous zooming, to make arranging controls easier.

Finally, if you have to create your own custom UI elements, the System.Windows.Media and System.Windows.Shapes namespaces contains a large selection of classes to render lines, circles, and other shapes directly in a window.

Help Creating Windows and ControlsFor step-by-step information about how to use these features, see the following Help topics.

Description Help topic

Creating a new WPF application with Visual Studio.

How to: Create a New WPF Application Project

Using controls in a window. How to: Select and Move Elements on the Design Surface

Creating event handlers for controls. How to: Create a Simple Event Handler

Handling events from a window and the window's controls.

How to: Use Attached Events

Navigating a WPF layout. Navigating the Element Hierarchy of a WPF Document

Creating dynamic layouts. Layouts in the WPF Designer

Creating custom controls. How to: Create a WPF UserControl Library Project

Collaboration with Expression Blend WPF provides a strong separation of content and presentation, which makes it possible for software developers and graphical designers to collaborate on the appearance and behavior of an application. The Windows Presentation Foundation (WPF) Designer for Visual Studio is optimized for software developers, and Expression Blend is optimized for graphical designers. For more information, see Collaboration with Expression Blend.

Deploying Applications to Client Computers After you have written your application, you must send the application to your users so that they can install and run it on their own client computers. When you use ClickOnce technology, you can deploy your applications from within Visual Studio by using just a few

Copy Rights 2009. Powered by Wits Square Technologies.

Page 19: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 19 of 28

clicks, and provide your users with a URL pointing to your application on the Web or file share. ClickOnce manages all the elements and dependencies in your application, and ensures that the application is correctly installed on the client computer.

ClickOnce applications can be configured to run only when the user is connected to the network, or to run both online and offline. When you specify that an application should support offline operation, ClickOnce adds a link to your application in the user's Start menu. The user can then open the application without using the URL.

When you update your application, you publish a new deployment manifest and a new copy of your application to your Web server or file share. ClickOnce will detect that there is an update available and upgrade the user's installation; no custom programming is required to update old assemblies. For more information, see WPF Application Deployment

Deploying ClickOnce ApplicationsFor a full introduction to ClickOnce, see ClickOnce Deployment Overview. For step-by-step information about how to use these features, see the following Help topics,

Description Help topic

Deploying an application by using ClickOnce.

How to: Publish a ClickOnce ApplicationWalkthrough: Manually Deploying a ClickOnce Application

Updating a ClickOnce deployment. How to: Manage Updates for a ClickOnce Application

Managing security with ClickOnce. How to: Enable ClickOnce Security Settings

User Interface Reference for the WPF DesignerThe Windows Presentation Foundation (WPF) Designer for Visual Studio enables you to create WPF applications in a familiar design-time experience. This topic describes some of the user interface elements found in the WPF Designer.

User Interface Elements

UI Element Description

Design view

Design view is the part of the designer that contains the WPF Window that is being designed.

Fit in view The Fit in view button automatically scales the view of the active Window to fit in Design view. The Fit in view button is located at the bottom of the Zoom control.

split view Split view contains both Design view and XAML view, and also the bar that joins the two views.

tag navigator

The tag navigator provides a navigable representation of the current XAML element, and allows you to select parent elements. The tag navigator is located at the bottom of the WPF Designer.

Window Window refers to the active design surface in Design view that represents a WPF window or user control.

WPF Designer

The WPF Designer is the Visual Studio designer that is used to create WPF applications. It collectively includes Design view and XAML view.

XAML view XAML view is the part of the designer that displays the XAML markup for the active Window.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 20: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 20 of 28

Zoom control

The Zoom control is located in the upper-left corner of Design view and allows the user to zoom in or out on the current Window by manipulating the Zoom control slider.

Updated with "SilverLight FAQ Part 1, Part 2 and Part 3" LinkUpdated with "WCF-Part 1" linkUpdated with "State Machine Workflow Discussion" linkUpdated with "One-Many and One-One relationship using LINQ to SQL" link

Windows Workflow Foundation FAQ

• Introduction • What is Windows Workflow Foundation? • What is a Workflow? • What are different types of Workflow in Windows Workflow foundation? • When should we use a sequential workflow and when should we use state machines? • How do we create workflows using designer? • How do we specify conditions in Work flow? • How do you handle exceptions in workflow? • What is the use of XOML files? • How can we pass parameters to workflow?

Introduction

In this FAQ we will quickly run through and get a feel of how WWF (Windows Workflow foundation) will help you in making custom work flows in your project.

I have been writing and recording videos for architectures. I have uploaded some sample videos for design pattern,UML,Function points at http://www.questpond.com/FreeDesign1.htm . You can visit http://www.questpond.com and download the complete architecture interview questions PDF which covers SOA , UML , Design patterns , Togaf , OOPs etc.

If you have not read my previous quick FAQ section you can always read from below:

• Part 1 Design pattern interview questions SoftArchInter1.aspx • Part 3 Design Pattern Interview questions Part 3 • Part 4 Design Pattern Interview questions Part 4 • UML Part 1 Interview questions UML Part 1 • UML Part 2 interview questions UML part 2 • Dependency injection IOCDI.aspx • SilverLight FAQ Part 1 :- http://www.codeproject.com/KB/WPF/WPFSilverLight.aspx • SilverLight FAQ Part

2 :-http://www.codeproject.com/KB/silverlight/SilverLightFAQPart2.aspx • SilverLight FAQ Part 3: -SilverLight Part 3 • Windows Communication Framework Part 1 • Windows Communication Framework Part 2 • Windows Presentation Framework WPF.aspx • State Machine Workflow Discussion StateMachine.aspx

Copy Rights 2009. Powered by Wits Square Technologies.

Page 21: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 21 of 28

• One-Many and One-One relationship using LINQ to SQL One-Many and One-One relationship using LINQ to SQL

Happy job hunting......

What is Windows Workflow Foundation?

WWF is a programming model for building workflow-enabled applications on windows. System. Workflow namespace has all the necessary modules to develop any type of workflow.

What is a Workflow?

A Workflow is a set of activities, which is stored as model and they depict a process. Below figure depicts clearly the difference between Workflow and Activity. Every task is an activity and group of activity depicts a complete workflow. Workflow is run by the Workflow runtime engine.

Figure 1: - Work Flow Foundation Architecture

Workflow model can be written in pure .NET code, pure XAML or Mix of XAML and .NET Code. A workflow model is compiled and can execute under windows, ASP.NET, Web services or windows services application.

What are different types of Workflow in Windows Workflow foundation?

There are two basics type of workflow Sequential Workflow and State machines workflow.A sequential workflow has clear start and finish boundaries. Workflow controls execution in Sequential workflow. In sequential execution, one task is executed after other. Sequential

Copy Rights 2009. Powered by Wits Square Technologies.

Page 22: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 22 of 28

workflow is more rigid in format and execution path has a deterministic nature.A State machine workflow is more dynamic in nature. Workflow has states and the state waits for events to help it move to next state. In State machine execution path is undeterministic nature.Below figure shows visual conceptualization of fundamentals. You can see in Sequential workflow the execution path is very determent. Shiv performs the entire task sequentially and these tasks are very determent. Now have a look at the second workflow. Every state goes to other state when it receives some external events. For instance when Shiv is seeing star trek there is an event of flashing news which triggers him to see the flashing new.

Figure 2: - Sequential and State machine workflow

When should we use a sequential workflow and when should we use state machines?

If the workflow is very rigid then you go for sequential workflow and if the workflow is dynamic then go for State machine workflow. For instance you have placed an order and the order will not pass until your supervisor approves is a rigid flow. Because your order has to be approved by, a supervisor or else it will not be approved. But what if your order moves from one place to other place. For instance, it moves from approval to waiting and then clarification a state machine workflow model is more appropriate.Below is a simple code snippet which shows practically how to use sequential workflow. Let try to understand step by step as marked in the figure:-1 - First you need to select System. Workflow namespace.2, 3, and 4 - In these three steps we created code object and linked them with activity.5, 6, 7, and 8 - We start the workflow and create workflow instance object to run the sequential workflow. You can see the output in 8. Depending on how you add the activity in

Copy Rights 2009. Powered by Wits Square Technologies.

Page 23: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 23 of 28

section 3, it executes sequentially. Because we have added codeactivity1, first it executes the first activity first. The sequence on how you add the activity to the activities collection the activities are run.

Figure: - 3 Code snippet for workflow

Note: - The above code snippet was developed with out using designer. The whole point was to make you understand what happens behind the scenes. In real projects you will be dependent on designer rather than coding manually. You can find the above code in SimpleWorkFlowSampleManual folder.

How do we create workflows using designer?

As said previously it is very easy to design workflows using designer. So we will answer this question by actually doing a small sample. Below is the code snippet and image snapshot which shows how we can use the designer to create workflows. So lets understand all the below numbered snapshot.

1. First select a sequential workflow project. In this case, we have selected Sequential workflow console application to keep the sample simple.

2. When you are done with creating the project you will see the solution explorer as shown in the second snapshot. There are two files one the WorkFlow1.cs and the other Workflow1.designer.cs.If you click on the WorkFlow1.cs you will get a designer

Copy Rights 2009. Powered by Wits Square Technologies.

Page 24: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 24 of 28

pane as shown in snapshot 3. If you double click on Workflow1.designer.cs, you will get behind code as shown in snapshot 4.

3. So let us drag drop a code activity on the workflow designer and associate this activity with a method called as MyActivity1. This association is done by entering the method name in Execute Code property. In MyActivity1, we have just displayed in the console that this is my first activity. Again, we have added one more code activity, which points to MyActivity2. If you see the designer pane we have sequenced code1 first and code2 next. So in short, code1 will execute first and the code2. This is clear from the output displayed below.

4. This is the behind code of the workflow.

Figure 4 Sequential workflow using designer

How do we specify conditions in Work flow?

Yes, you can define conditions in workflow by using conditionedActivitygroup. Below is the numbered snapshot, which shows how to use conditionedActivitygroup.

1. You can see in this snapshot we have defined a conditionedActivitygroup with two conditions. The two boxes inside the group define two conditions.

2. You can select one of the condition box and define the condition using the When Conditions property. If this condition is true you need to specify in the execute code which method to execute. For instance in the current snapshot we have said that

Copy Rights 2009. Powered by Wits Square Technologies.

Page 25: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 25 of 28

old1 method should execute if age > 21. The same procedure we need to follow for the second condition box. In the second condition box we have specified to execute young1 method if age < 21. Currently the second condition is not visible in the below snapshot.

3. Workflow editor also provides a cool interface called as Rule Condition Editor, which can be used to specify conditions. Age is a public property in the behind code. You can also get the Age in the intelligence of rule condition editor.

4. Both the condition will execute inside the condition activity group. We need to also specify when this conditionactivitygroup should exit. Therefore, we have made a function called as exit. If the user inputs age as -1 it will exit from the loop or else it will take inputs from user and continue evaluating depending on the two conditions.

Figure 5:- Sequential workflow with conditions

How do you handle exceptions in workflow?

Exception handling in Workflow is somewhat different than how we do in normal .NET application. Below is the numbered snapshot of how we can handle exceptions in Workflow.

1. We have small tab, which says view exceptions. If you click on view exception, you will be redirected to a workflow design only for exception as shown in numbered snapshot 2.

Copy Rights 2009. Powered by Wits Square Technologies.

Page 26: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 26 of 28

2. This is the workflow which will execute incase we have exceptions. We have put a code activity, which points to a method called as raise Exception. Incase of exception in the workflow this path will be followed.

Figure 6:- Workflow with exception handling

What is the use of XOML files?

Twist: - How can we serialize workflows?

Windows Workflow Foundation gives developers a declarative way to create workflows by using XAML. See WPF chapter for more details about XAML. These markup files are Stored with XOML (Extensible Object Markup Language) extension. In the below snapshot you can see Workflow1.xoml file created by designer. Markup file can also have code behind. The whole concept of having code behind for XOML file is to separate the presentation from logic files.In the below code snapshot we have made a simple XOML sample. Below is the explanation number wise:

1. In order to create a XOML file you need to add sequential workflow with separation. Which means that XOML file will be created with a behind code.

2. Currently we have two activity code3 and code1. Below is the XOML file contents:

Collapse Copy Code

Copy Rights 2009. Powered by Wits Square Technologies.

Page 27: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 27 of 28

<?Mapping XmlNamespace="ComponentModel" ClrNamespace="System.Workflow.ComponentModel" Assembly="System.Workflow.ComponentModel" ?><?Mapping XmlNamespace="Compiler" ClrNamespace="System.Workflow.ComponentModel.Compiler" Assembly="System.Workflow.ComponentModel" ?><?Mapping XmlNamespace="Activities" ClrNamespace="System.Workflow.Activities" Assembly="System.Workflow.Activities" ?><?Mapping XmlNamespace="RuleConditions" ClrNamespace="System.Workflow.Activities.Rules" Assembly="System.Workflow.Activities" ?><SequentialWorkflow x:Class="WorkflowSeq.Workflow1" x:CompileWith="Workflow1.xoml.cs" ID="Workflow1" xmlns:x="Definition" xmlns="Activities"><Code ExecuteCode="Mycode3" ID="code3" /><Code ExecuteCode="Mycode1" ID="code1" /></SequentialWorkflow> See the above snippet of the XOML file. You can see how the behind code is linked using the Compile With attribute. Code forms the element of the Sequential Workflow tag. One of the best thing with Markup is we can change the sequence just by changing the XOML file we do not need to compile the whole application again.

Figure 7:- XOML in action

Copy Rights 2009. Powered by Wits Square Technologies.

Page 28: Page 1 of 28 · The global acceptance of Web services, which includes standard protocols for application-to-application communication, has changed software development. For example,

Page 28 of 28

In the above snapshot, one of the things to now is 3, 4, and 5 numbered sections. These sections are not linked with the sample. But just to make you aware you can create serialize any workflow and deserialize them again using the text writer object.

How can we pass parameters to workflow?

When you call the start workflow function, you can pass as name / value pairs using the dictionary object.

Figure 8:- Passing value to workflow

Copy Rights 2009. Powered by Wits Square Technologies.