(WCF) support

advertisement
Author: Manish (Manish Paul/India/IBM)
1. Introduction
This article covers WCF modeling concepts for Visual Basic application developers. The
article presumes that you are already familiar with Visual Basic modeling and
transformations (Conceptual and Reconcile) concepts.
2. WCF service modeling and code generation
RSA provides modeling support for WCF service components, including modeling
Service Contracts, Data Contracts, and Message Contracts. With the .NET WCF profile,
you represent WCF constructs in a UML model (see Figure 1). The profile has
representation options for almost all of the attributes supplied by the WCF framework to
design a WCF service library. Each stereotype provides a set of properties for specifying
different parameters of a WCF attribute.
Figure 1. WCF stereotypes
Author: Manish (Manish Paul/India/IBM)
WCF profile can be applied in conjunction with VISUAL BASIC profile for specifying
VISUAL BASIC specific properties alongside WCF properties. The following sub
sections talk about the individual stereotypes for WCF service modeling. If WCF
stereotypes have been applied, forward transformation using UML-to-VISUAL BASIC
will generate code accordingly.
Service Contract
A WCF service can be defined by either a class or by an interface with groups of
operations that define the offerings of the service. The Service Contract ties together
multiple related operations into a single functional unit. To create a Service Contract,
operations are grouped together, either by declaring them within an interface marked with
the ServiceContract attribute, or by defining them in a class marked with the same
attribute. WCF services define the operations by creating a method and marking it with
the OperationContract attribute.
For modeling a Service Contract, you can apply the Service Contract stereotype
(Figure 4) on a class or an interface. The contract can define service-level settings, such
as the namespace of the service, a corresponding callback contract, and other such
settings through Service Contract properties. It also defines a set of operations with the
Operation Contract stereotype applied to them and the Parameters value set.
Author: Manish (Manish Paul/India/IBM)
Internal execution behavior of a Service Contract implementation can be specified with
the Service Behavior stereotype. Apply the Service Behavior stereotype to a service
implementation to specify service-wide execution behavior. To specify execution
behavior at the method level, use the Operation Behavior stereotype
You can use the Callback Behavior stereotype to configure or extend the execution
behavior of a callback contract implementation in a client application. This attribute
performs the same function for the callback class as the ServiceBehavior attribute,
with the exception of instance behavior and transaction settings.
The Transaction Flow stereotype on an Operation Contract specifies whether a
service operation accepts incoming transactions from a client.
Data Contract stereotype
All Service Contracts have an associated implicit or explicit Data Contract, which defines
the data that the service works on. The data types that 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.
Rational Modeling Extension allows specifying the Data Contract with the help of the
Data Contract stereotype. A data contract can have multiple data members, which are
specified by applying the Data Member stereotype on a UML property, a VISUAL
BASIC property, and such.
The parameters in the Data Contract must be of types that can be serialized. WCF
supports a serialization engine, the XmlSerializer, which can also be used to serialize
parameters. To switch to using the XmlSerializer for a particular operation or for the
entire service, apply the XmlSerializerFormat stereotype to an operation or a service.
Message Contract stereotype
A single type can be used to represent the entire message. Although it is possible to use a
Data Contract for this purpose, the better way to do this is to use a Message Contract,
because it avoids unnecessary levels of wrapping in the resultant XML. Additionally,
Message Contracts allow exercising more control over resulting messages. For instance,
you can specify which pieces of information should be in the message body and which
should be in the message headers.
A Message Contract describes the format of a message. For example, it declares whether
message elements should go in headers rather than in the body of the message (source:
MSDN Library, cited in Resources).
Author: Manish (Manish Paul/India/IBM)
The Message Contract stereotype can be applied on class for describing a message with
Message Header and Message Body Member stereotypes for properties/fields.
Specifying faults
In all managed applications, Exception objects represent processing errors. In WCF
applications, service methods communicate processing error information by using fault
messages.
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. In
Rational Modeling Extension, the Fault Contract stereotype can be applied on an
Operation Contract. Given that a stereotype can be applied only once on a single element,
you can apply the Fault Contract stereotype to an operation only once. However, if
you want to add more Fault Contract for an operation, you can type the fault contract
description string in the attributes property of the VB Method stereotype.
Default values for stereotype properties
The stereotype properties, which are of Boolean, integer, or enumeration types, have been
assigned default values in the profile. Table 1 lists the default values for the properties of
the CallBack Behavior stereotype. When a stereotype property is set to default value,
the transformation does not generate the corresponding named parameter for
corresponding WCF attribute. If all the properties are set to default values, transformation
generates only the attribute without any parameter. This essentially means that the WCF
attribute will utilize the default constructor. Whenever there is a value for the property
different from the default, transformation generates the named parameter for that.
Table 1. Default values for Properties
Stereotype
CallBack
Behavior
Properties
AutomaticSessionShutDown
ConcurrencyMode
IgnoreExtensionDataObject
IncludeExceptionDetailInFaults
MaxItemsInObjectGraph
TransactionIsolationLevel
TransactionTimeout
UseSynchronizationContext
ValidateMustUnderstand
Type
Boolean
ConcurrencyMode
Boolean
Boolean
Integer
IsolationLevel
String
Boolean
Boolean
Default
True
Single
False
False
65536
Unspecified
--True
True
Download