Cet article concerne Visual Studio 2010 Beta1. Les informations peuvent ne pas être véritables lors de la sortie de la version finale du produit.
La procédure suivante permet de créer un workflow simple et de le déployer dans IIS 7.
Créer un nouveau projet dans VS 2010 : File | New | Project…
Créer un projet de type Declarative Flowchart Service Library :
Un projet de service sera alors créé possédant un nouveau service Service1.xamlx. (Normalement, dans les versions ultérieures, il ne devrait plus y avoir d’extension xamlx, mais bien xaml)

Renommer le fichier pour : WriteLineService.xamlx.
Ouvrir le workflow en utilisant l’éditeur XML (Menu contextuel du fichier: Open With) et changer le nom du service et le nom du contrat:
<Service mc:Ignorable="sad1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sad1="http://schemas.microsoft.com/netfx/2009/xaml/activities/design" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:w="clr-namespace:WriteLineService;assembly=WriteLineService" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<WorkflowServiceImplementation ConfigurationName="WriteLineService" Name="WriteLineService">
<p:Flowchart DisplayName="FlowchartService" sad:XamlDebuggerXmlReader.FileName="C:\Users\Karol\Documents\Visual Studio 10\Projects\WriteLineService\WriteLineService\WriteLineService.xamlx">
<p:Flowchart.StartNode>
<p:FlowStep x:Name="__ReferenceID0">
<p:FlowStep.Next>
<p:FlowStep x:Name="__ReferenceID1">
<p:FlowStep.Next>
<p:FlowStep x:Name="__ReferenceID2">
<sad1:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, s:Object">
<av:Point x:Key="ShapeLocation">86.1266666666667,359.03953125</av:Point>
<av:Size x:Key="ShapeSize">207.746666666667,81.9209375</av:Size>
</scg:Dictionary>
</sad1:WorkflowViewStateService.ViewState>
<SendReply DisplayName="SendResponse" ValueType="x:String">
<SendReply.Request>
<Receive x:Name="__ReferenceID3" CanCreateInstance="True" DisplayName="ReceiveRequest" OperationName="GetData" ServiceContractName="IWriteLineService" ValueType="x:Int32">
Ouvrir le fichier web.config et remplacer toutes les instances de Service1 par WriteLineService.
Ajouter les deux endpoints suivants :
<service name="WriteLineService" behaviorConfiguration="WriteLineService.WriteLineServiceBehavior" >
<endpoint address="" binding="wsHttpBinding" contract="IWriteLineService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
Créer une classe Helper.cs pour écrire dans le journal des événements :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;
namespace WriteLineService
{
public static class Helper
{
public static string WriteToEventLog(string text)
{
if (!EventLog.SourceExists("WF"))
EventLog.CreateEventSource("WF", "Application");
EventLog.WriteEntry("WF", text);
return text;
}
}
}
Compiler le projet et réouvrir le workflow pour ajouter une activité InvokeMethod et la paramétrer pour appeler la méthode de la classe précédente. Ajouter aussi un paramètre à l’appel de méthode avec la valeur “Hello world!”.
Relier la première activité à la nouvelle et cette dernière à l’activité d’envoi de message.
Dans les propriétés du projet, onglet web, sélectionner Use local IIS web server et cliquer sur Create Virtual Directory.
Recompiler le tout et accéder à l’adresse suivante pour valider que le service est en marche :
http://localhost/WriteLineService/WriteLineService.xamlx
(Note : Pour le Beta1, il est requis de supprimer la dll PresentationCore qui se trouve dans le répertoire Bin du service.)
Créer un client avec une référence service et tester l’appel. Normalement, le journal des événements devrait contenir une entrée avec le texte spécifié dans l’activité.