Getting started with Windows Workflow Foundation (WWF)
Posted by
Manas
at
1:26:00 AM
Reactions:
Windows Workflow Foundation (WWF) is one of the key pillars of the .NET Framework 3.0 (formerly known as WinFX), next to Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF) and Windows CardSpace (WCS).
Now we ready to start a simple WWF example which demonstrated as bellow in steps. This example I demonstrated by using VS 2008 but you can do it in VS 2005 also by downloading the template from the bellow link:
STEP: 1 Start Visual Studio 2008 and select create new project and Choose for a Sequential Workflow Console Application. Let's named it HelloWorkflow . In the solution explorer, delete Workflow1.cs. Although this is not necessary it's interesting to create the workflow in another way, using "code separation" with XOML (which stands for eXtensible Object Markup Language).

![]() |
| Click on image to see in big size |
STEP: 2 Then add a new item to the project and choose for Sequential Workflow (with code separation) and named it HelloWorkflow. As you can see, it has the extension .xoml.
![]() |
| Click on image to see in big size |
STEP: 3 Workflows consist of activities that are executed in a well-defined order by the workflow runtime engine. These activities can be found in the Visual Studio 2008 toolbox, but it's also possible to create your own activities.The tool box looks like as follows:
Labels: Advanced 0 comments
A Silverlight Application By Using ADO.NET DataEntities and WCF Service
Posted by
Manas
at
8:41:00 PM
Reactions:
Before we start this application we have to install the following pre-requisite software:
- Visual Studio 2008 with SP1 or Visual Studio 2010
- SQL Server 2005 or later version
- Silverlight 3 or later version with full toolkits
After installed the above pre-requisites we are now ready to start our application.
STEP: 1. Ready the database which will be use in our application. Here I am using the local database called DG in which Tab_Emp is the table.
STEP: 2. Create a new Silverlight project, named SilverlightWcfEntities, and accept the default of creating an ASP.NET Web Application.
Visual Studio will create one solution with two projects:
- SilverlightWcfEntities (the Silverlight project)
- SilverlightWcfEntities.Web (the Web project)
The second project will house both the ADO.NET Entity model and the web service, while the first will hold the Silverlight DataGrid.
STEP: 3. To create the Data Model, right click on SilverlightWcfEntitities (the web project) and select Add >>> New Item. Choose Ado.Net Entity Data Model, name it EmployeeDataModel.edmx and click the Add button.
In the next dialog click on the Generate from Database button – this will, ultimately, because the data model to be created for you, a wonderful thing saving you endless boring work. The next dialog will ask you to choose the data connection you’d like to use.
And once the connection is made and the data structure retrieved, you’ll be asked to select which tables, views and stored procedures you’d like included in your model. Here I selected just one table: Tab_Emp. We can select stored procedure and views also.
When we click Finish, our entity data model is generated. Spend a couple minutes looking at the result, it is quite cool. Note there may be a window hiding at the bottom of Visual Studio named Mapping Details. Examine the result of that window.
STEP: 4. With the Entity Data Model in place we’re ready to create a web service to make the data available to the Silverlight application that will be running on the client.
Open EmployeeWebService.svc.cs where we will find a stub method, DoWork() which we will modify to fetch the list of employees.
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class EmployeeWebService
{
[OperationContract]
public List<Tab_Emp> GetEmployees()
{
EmployeeEntities empEntity = new EmployeeEntities();
return empEntity.Tab_Emp.Where(emp => emp.DeptName.Equals("Developer")).ToList();
}
// Add more operations here and mark them with [OperationContract]
}
The first line of the GetEmployees() method creates an instance of the Data Entity that we defined earlier.
The second line asks the data entity instance for the Employee objects, but since there are a lot of them, it adds a where clause, using a lambda expression to narrow the return set and then calls ToList() on the result effectively casting the result set to a List.
STEP: 5. Lets now move to silverlight application named SilverlightWcfEntities (the Silverlight project) and right click on that project and select reference >>> Add Service Reference. On that dialog click on Discover. The Web Service we created earlier (EmployeeWebService) will appear in the list. Click on it and then rename the namespace to EmployeeWebService.
After getting the service reference we’ll start working on MainPage.xaml of the SilverlightWcfEntities (the Silverlight project). First we drag a datagrid from the toolbox which makes the code like this:
<UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="EntitiesWebSvcGrid.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot" Background="White">
<data:DataGrid x:Name="dg" >data:DataGrid>
Grid>
UserControl>
Then switch to the MainPage.xaml.cs and there we have to to create an instance of the web service client and then use that client to call the GetEmployees method on the web service. Write this method in Page_Loaded() event.
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
EmployeeWebService.EmployeeWebServiceClient ws = new EntitiesWebSvcGrid.EmployeeWebService.EmployeeWebServiceClient();
}
Because Silverlight applications run in the browser, however, we cannot make direct method calls (you must not block the browser) but rather must make asynchronous calls. In fact, Intellisense not only offers an async alternative, it does not even offer the synchronous method we created. So we have to call the GetEmployeeAsync method for that. After which we have to define another event called GetEmployeeCompleted where we set the data source for our grid in runtime.
So please don’t worry just compare your whole code as shown bellow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace EntitiesWebSvcGrid
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
EmployeeWebService.EmployeeWebServiceClient ws = new EntitiesWebSvcGrid.EmployeeWebService.EmployeeWebServiceClient();
ws.GetEmployeesCompleted += new EventHandler GetEmployeesCompletedEventArgs>(ws_GetEmployeesCompleted);
ws.GetEmployeesAsync();
}
void ws_GetEmployeesCompleted(object sender, EntitiesWebSvcGrid.EmployeeWebService.GetEmployeesCompletedEventArgs e)
{
dg.ItemsSource = e.Result;
}
}
}
Now its its time to see the output of the whole process. So just press F5 and here we go…
Note: number of rows may be differing according to the data you have.
Hope It Helps..!
Labels: Advanced 0 comments
Subscribe to:
Posts (Atom)















