Click here to Skip to main content
13,352,428 members (38,848 online)
Click here to Skip to main content
Add your own
alternative version


67 bookmarked
Posted 17 May 2010

Writing a 'Hello World' program using wpf+wcf+wf step by step

, 17 May 2010
Rate this:
Please Sign up or sign in to vote.
Writing a 'Hello World' program using wpf+wcf+wf step by step


In my development,I use WF to do business logic ,and use wpf to do UI ,and use WCF to do communication.

Yesterday, I saw one post:what is the WCF,WPF,WF anybody can u give me the brief ? ,So I want to write an article to express my point of view.

A "hello world" program has become the traditional first program that many people learn. So I decide to write this 'Hello World' program with wcf+wpf+wf to express it .

About the Code

This example is very simple, just use the WPF, WCF, WF three new technologies. This example has three project:

WPFProject:A WPF Application ,It is used to implement the UI

WFProject:WF4 can be used to customize the business logic, this case I just use it to call the WCF service

WCFProject:A Console Application,It is used to otain data: ‘hello world’

The WPFProject start WFProject's workflow, WFProject call WCFProject 's WCF Service. Then WCFProject return 'Hello World' to the WFProject, Last WFProject retun 'Hello World' to the WPFProject's UI. Implementation of the order as shown below:


Figure 1

Implementation steps

Create a new WpfApplication, a newConsoleApplication, a workflow of ActivityLibrary, a total of three projects, named respectively: WPFProject, WCFProject, WFProject,as show below:


Figure 2


1、Because it is a console application, so I need to add System.ServiceModel.dll reference


Figure 3

2、Add an interface IService1 for Contract

public interface IService1 
string GetData(); 

3、Add a class Service1 to implement IService1:

public class Service1 : IService1
    public string GetData()
        return string.Format("Hello World");

4、 Deploy App.config with Address and Binding for wcf service:

<service name="WCFProject.Service1" behaviorConfiguration="metadata"> <host>
<add baseAddress="http://localhost:8001/Service1"/>
<endpoint binding="basicHttpBinding" contract="WCFProject.IService1"/> </service>
<behavior name="metadata">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

5、Add the following code in the Program.cs to start wcf service :

using (ServiceHost host = new ServiceHost(typeof(Service1)))
    Console.WriteLine("The service is ready.");
    Console.WriteLine("Press <enter /> to terminate service.");


If you are not familiar with WF, see this

1、Drag and Drop a SendAndReceiveReply to Activity1,as show below.


Figure 4

2、Send:I use this Send Acitivy to call the WCF service.Please note.

a)、OperateName: GetData .(WCF Method)

b)、 EndPoint : EndPoint

c)、Binding : basichttpBingding.(WCF Binding)

d)、EndPointAddress:New Uri ("http://localhost:8001/Service1") (WCF Address)

e)、ServiceContractName :IService1.(WCF Contract)

3、ReceivReplyForSend: I use this ReceivReplyForSend Acitivy to obtain the return value of the WCF service

a)、Add an output parameter:returnValue.


Figure 5

b)、Content as show below:


Figure 6

4、The entire workflow as show below:


Figure 7


In this Demo, this proect is very easy , the relationship between WPF and WF is the reference dll. WPFProject reference WFProject.dll.So

1、Reference WFProject.dll、System.Activities.dll in the WPFProject


Figure 8


Figure 9

2、In MainWindow Form drag a button, change the Content: "Invoke Workflow", in the click event add the following code:

IDictionary<string, object> results = WorkflowInvoker.Invoke(new Activity1());


Start WCFProject, as shown below:


Figure 10

Start WPFProject. Click Invoke Workflow, the results below:


Figure 12

Points of Interest

This article use the most simple Hello World program teach you to use three kinds of the latest technology. I think this is a good way to development

WPF:UI presents(In client)

WF:Business logic (In server or In client )

WCF:Data communication (In server)

This is my first article on codeproject, my first language is not English.I hope you give me some advice to improve


Keep a running update of any changes or improvements you've made here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Kirin
China China
No Biography provided

You may also be interested in...


Comments and Discussions

Generalplease let me know how to do in web application with sample code Pin
chandru22210-Nov-10 21:35
memberchandru22210-Nov-10 21:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 17 May 2010
Article Copyright 2010 by zhuqil
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid