Create a hello World program using WPF, WCF, and WF

Source: Internet
Author: User

Http://www.codeproject.com/KB/WF/wcf-wpf-wf-hello-world.aspx

Analysis: 

As the initial stage of all programming languages, the hello World program occupies an unchangeable position. This example is simple. It uses three relatively new technologies: WPF, WCF, and WF. In this example, there are three projects:

1. wpfproject:WPF applications

2. wcfproject:WCF Service

3. wfproject:WF Process Definition

The execution sequence is that the wpfproject program starts the workflow of the wfproject, And the wfproject project calls the wcfproject's WCF Service. Then, the wcfproject service returns the most classic words in the 'hello world' field to the wfproject. The wfproject will return 'Hello world' to the UI of the wpfproject. The execution sequence is as follows:

Implementation:

Create a wpfapplication, consoleapplication, and activitylibrary for workflow. The three projects are named wpfproject, wcfproject, and wfproject respectively. The solution is as follows:

 

We implement the hello World Program in the code generated by the vs template. We try to use the generated code as much as possible.

The least familiar with WCF:

Reference System. servicemodel. dll

Add interface iservice1:

1 [servicecontract]
2 public interface iservice1
3 {
4 [operationcontract]
5 string getdata ();
6}

Add a class service1:

1 public class service1: iservice1
2 {
3 Public String getdata ()
4 {
5 return string. Format ("Hello World ");
6}
7}

App. config Configuration:

1 <? XML version = "1.0" encoding = "UTF-8"?>
2 <configuration>
3 <system. servicemodel>
4 <services>
5 <service name = "wcfproject. service1" behaviorconfiguration = "metadata">
6 7 <baseaddresses>
8 <add baseaddress = "http: // localhost: 8001/service1"/>
9 </baseaddresses>
10 11 <! -- The basichttpbinding is used because the workflow uses a generated ASP. NET proxy to communicate with this service -->
12 <endpoint binding = "basichttpbinding" Contract = "wcfproject. iservice1"/>
13 </service>
14 </services>
15 <behaviors>
16 <servicebehaviors>
17 <behavior name = "metadata">
18 <! -- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
19 <servicemetadata httpgetenabled = "true"/>
20 <! -- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
21 <servicedebug includeexceptiondetailinfaults = "false"/>
22 </behavior>
23 </servicebehaviors>
24 </behaviors>
25 <servicehostingenvironment multiplesitebindingsenabled = "true"/>
26 </system. servicemodel>
27 </configuration>

Add the following code to start the WCF Service in program. CS:

1 using (servicehost host = new servicehost (typeof (service1 )))
2 {
3 host. open ();
4 console. writeline ("the service is ready .");
5 console. writeline ("press <enter> to terminate service .");
6
7 console. Readline ();
8}

The above implements a simple WCF Service, so that the wcfproject is complete.

The most familiar WF:

Support a sequence on activity1, and then send a send activity on sequence to call the defined WCF Service.

Add a returnvalue output parameter that stores the returned values.

Send activities need to know the ABC of the WCF Service. Make the following settings.

1. operatename: Getdata (same as the name of the above WCF method)

2. endpointSet to endpoint

3. bingdingSet to basichttpbingding.

4. endpointaddressSet it to new uri ("http: // localhost: 8001/service1"), which is the same as the address of APP. config in wcfproject.

5. servicecontractnameSet it to the interface name iservice1 of the WCF Service.

Right-click the send activity and select create extension reply to create a replica reply. You need to set an attribute: Click content to set it as follows:

The final process is shown in:

This completes the workflow project.

The last WPF

Since wpfproject and wfproject are directly referenced, wpfproject directly references the DLL of wfproject, for example.

To start WF, you also need to add the system. Activities. dll reference of the workflow.

Drag a button in the mainwindow form and change the text to "invoke workflow". Add the following code in the click event:

1 idictionary <string, Object> Results = workflowinvoker. Invoke (New activity1 ());
2
3 MessageBox. Show (results ["returnvalue"]. tostring ());

This completes the wpfproject.

Debugging and result:

Start wcpproject, for example:

Start wpfproject. Click invoke workflow. The result is as follows:

 

Summary:

The Hello world program is implemented in combination with WPF, WCF, and WF.

This article uses the simplest Hello World program to teach you how to use the three latest technologies. Is it worth your suggestion? Thank you. :)

Code:/Files/zhuqil/wpfwcfwf.rar

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.