You can generate code that
is compatible with the REST Windows Communication Foundation (WCF) service library by applying stereotypes
from the Representational State Transfer (REST) and .NET Windows Communication Foundation (WCF) profiles
to elements in a REST model.
Before you begin
You must have the REST modeling
capability enabled.
To generate WCF service library code, your
REST model must have at least one class or interface that has the
«Resource» stereotype applied. To model REST-specific WCF attributes,
other than the «Resource» stereotype, you must also use the «ServiceContract»
stereotype.
Procedure
- To create a model project and a model from the REST Service Model template, complete the following steps:
- Click , and complete the pages in the Model Project wizard
- On the Create Model page of the
wizard, in the Categories pane, click REST Modeling, then in the Templates pane, click REST Service Model.
- Optional: Complete the remaining pages in
the wizard.
- Click Finish. The modeling project is displayed in the Project Explorer view and the model has theREST profile
applied.
- In the model, create an interface or a class and apply
the «Resource» stereotype, which is in the REST profile. To create
a model with the REST-specific WCF attributes, other than the «Resource»
stereotype, also apply the «ServiceContract» stereotype.
- Create a UML-to-C# or C#-to-UML transformation configuration:
Click ,
and complete the steps in the wizard. Specify the following values
in the transformation configuration file:
- On the Specify a Configuration Name and Transformation page, in the Protocol
field, select Reconciled.
- On the Extensions page, for each
transformation select the check box that corresponds to the REST support
extension.
- On the WCF REST page, select the Route table generation information check box to specify
the parameters for generating the route table in the UML-to-C# transformation
or in the C#-to-UML transformation, for extracting the information
from the method of the class that you specify in the Method
for generation of route table field, and for generating
path dependencies in the UML model.
- On the same WCF REST page, click Generate REST stereotypes only to apply only the REST stereotypes
on the reverse transformation. Alternatively, if you want to apply
both the WCF and REST stereotypes,
click Generate both REST and WCF stereotypes. By selecting any of these options for generating stereotypes,
you can resolve the conflict of identical information in a model element
where both the REST and WCF stereotypes are applied.
- Click .
What to do next
You can now run the transformation. For information about
running transformations, see the related link at the end of this topic.