Implementing Service Logic Declaratively
With the contract definitions and projections in place, the next step is to actually implement the service logic in XAML. To do that, you need to encapsulate the details of the implementation in a <Service.Implementation> element. The following structure shows the <Service> element children required to define a service contract:
<!-- service contract definition goes here -->
<!-- service implementation goes here -->
<!-- service end points go here -->
Table 1 shows the elements you need to declare WCF services in XAML.
Table 1. WCF Declarative Elements: The table lists and provides a brief explanation of the elements used to express a WCF service declaratively in XAML.
||Acts as a root element that contains all the details of the service including the endpoint, service implementation, and so on.
||Lets you specify the contract projections exposed through a service
||Holds implementation logic for a declarative service
||Specifies the name of the service implementation that contains the workflow implementation
||Contains the body of the actual workflow implementation
||Specifies the service end point; contains an <Endpoint> element for each end point the service exposes
||Specifies details of the service, including the name of the service interface
||Specifies details of the operation, such as the name of the operation
||Specifies the names and direction of arguments supplied to the operation.
||Lets you define variables and associate them with a workflow that implements the operation
Listing 1 contains the complete service definition for a service interface named IHelloWorld, which exposes a method named HelloWorld().
Note that Listing 1 contains the actual service implementation inside the <WorkflowServiceImplementation.Body> element. That element contains the <ServiceOperation.Body> element, which uses the <DynamicActivityAction> element to specify the input and output variables to the workflow operation:
<Variable x:Name="op1" x:TypeArguments="p:String" />
You assign the input variable as the output from the HelloWorld method through the <wma:Assign> element:
<wma:Assign x:TypeArguments="p:String" To="out
[HelloWorldResult]" Value="op1" />
Then you define the service endpoint using the <Service.EndPoints> element, in which you specify the end point URI as well as the type of the binding (BasicHttpBinding in this case):
After you have the end point defined, you can specify the contract projections that will be made available for the IHelloWorld service through the <EndPoint.ContractProjection> element:
<OperationArgument Name="op1" Type="p:String"/>
That’s all there is to exposing a WCF service through XAML declaration. Although at first the XAML looks a little intimidating, you'll find that it becomes very straightforward after you've created a few of these.