What is WF series? [build a data logic layer based on WF and WCF]

Source: Internet
Author: User
Tags jbpm biztalk
What is WF series? [build a data logic layer based on WF and WCF]

What is WF? Many people who have some knowledge about NET technology can say something, but they cannot make it clear.

No matter what you think WF is, do not compare it with Jbpm, Shark, Biztalk, and SharePoint. These products share the same characteristics as products for enterprise business process applications, WF-oriented developers

WF is a process-oriented development platform that uses XML Description and has IOC and AOP functions.

 

I have been engaged in workflow development for eight years, and I have been studying WF for five years. I have been writing a blog on the WF topic in the blog garden for almost four years, I have been explaining the differences between WF and traditional workflows since I got started with WF. The following are some articles on this.

 

WF is not a Workflow
2007-05-17

 

WF is not a workflow (subsequent)
2007-05-18

 

Talking about WF
2007-0

 

Comparison between WF and Windows
2008-06-14

 

Why do we need WF?

 

 

Maybe I am engaged in workflow development. I learned from WF and used WF to develop workflows, so many people who read my blog mistakenly think that WF is like Jbpm, Shark, Biztalk, SharePoint.DedicatedDeveloping Enterprise Business Processes.

 

The articles listed above are marked with the writing date, which proves that I have been explaining this question to everyone, but it seems that it is not enough. so I decided to write another series and use some specific applications to fully introduce WF.

(I will not repeat the previously written content. If you want to know more about WF, you can read the articles listed above.

 

If you are a friend who developed COM + and read the example today, you will find that the idea of this example is very similar to that of using COM + to build the data logic layer.

In fact, WF3.X + WCF is an alternative to COM +. However, due to some changes in WF4.0, MS provides independent services for publishing WCF and WF, this method is more like COM + than WF3.X + WCF. I will write another series of such content. The following is an example of this article.

Build a data logic layer based on WF and WCF

 

Download this example:

Http://files.cnblogs.com/foundation/WFWCF.rar

 

Project Description

Data warehouse, in the wfwcf.rar File

 

 

 

Generally, a [data logic layer] is built when an enterprise application is built. The general structure is as follows:

 

 

This example uses a simple example to explain how to build a [data logic layer] Based on WF and WCF.

 

Let's take a look at the database structure in this example.

 

 

This is a simple database, but this structure is basically the initial model of the enterprise application data used

 

 

Let's talk about data operations.

In essence, the data operation is to [add, query, delete, modify] A table. In fact, it is very easy to [add, query, delete, modify] a single table,

 

I usually set the workload of a traditional SQL statement [add, query, delete, modify] to (1 * number of fields in the table)

 

If there are 10 unrelated tables, the workload will be (1 * number of fields in table 1) + (1 * number of fields in table 2 )... (1 * The number of fields in table 10)

 

This kind of work is simple. In fact, if it is such a structure, I will not build the [data logic layer], and directly UI to the database, a page for a table.

 

However, in fact, there is a thing (relationship/constraint) between the table and the table. Now the problem is complicated.

Hypothesis

[Table A. ID] constraint [Table B. ID]

When processing table [Table A], consider [Table B]. When processing table [Table B], consider [Table A]. the biggest problem is that when you add [Table. ID] constraint [Table C. ID.

In many cases, the code that actually processes data is very simple, and a lot of time is wasted on (relational/constraint) judgment.

 

In this example, I will change the database operation to an independent single table [add, query, delete, modify] operation, and hand over the (relational/constraint) judgment to WF for it.

 

Table operation code

Class Structure of the TabB table

[DataContract ()]


Public
Class
TableB

{

[DataMember ()]


Public
String RowID

{Set; get ;}

 

[DataMember ()]


Public
String ID

{Set; get ;}

 

[DataMember ()]


Public
String Value

{Set; get ;}

}

 

The following are several methods:


Public
Static
Class
DbManage

{


Static
String connectionString = "Data Source =.; Initial Catalog = testDB; Integrated Security = True ";

 


// Is there a [ID] In the table [TabA?


Public
Static
Bool checkIDinTabA (string ID)

{


Using (System. Data. SqlClient. SqlConnection con = new System. Data. SqlClient. SqlConnection (connectionString ))

{

Con. Open ();


Var command = con. CreateCommand ();

Command. CommandText = string. Format ("select ID from TableA where ID = '{0}'", ID );


Object obj = command. ExecuteScalar ();

Con. Close ();


If (obj = null)

{


Return
False;

}


Else

{


Return
True;

}

}

 

 

}


// Whether the specified [RowID] record exists in the table [TabB]

 


Public
Static
Bool checkRowIDinTabB (string RowID)

{


Using (System. Data. SqlClient. SqlConnection con = new System. Data. SqlClient. SqlConnection (connectionString ))

{

Con. Open ();


Var command = con. CreateCommand ();

Command. CommandText = string. Format ("select RowID from TableB where RowID = '{0}'", RowID );


Object obj = command. ExecuteScalar ();

Con. Close ();


If (obj = null)

{


Return
False;

}


Else

{


Return
True;

}

}

}

 


// Add records to the table [TabB]


Public
Static
Void insertTabB (TableB row)

{

 


Using (System. Data. SqlClient. SqlConnection con = new System. Data. SqlClient. SqlConnection (connectionString ))

{

Con. Open ();


Var command = con. CreateCommand ();

Command. commandText = string. format ("insert into TableB (RowID, ID, Value) values ('{0}', '{1}', '{2}')", row. rowID, row. ID, row. value );

Command. ExecuteNonQuery ();

Con. Close ();

}

}

}

 

(After reading this Code, some people may say that they do not apply exception capture, transaction, or lock to database operations. Is it omitted because it is an example. the answer is exception capture, transactions, and locks are all designed in WF)

 

Only the above Code can directly use insertTabB (TableB row), because the RowID may have a potential key conflict with the ID.

Therefore, [Add a record to the table [TabB] We need to perform the following business logic judgment:

 


 

 

Use WF in the WCF Service to implement the above business logic

 

Add the following variables

 

Add a flowchart

 

For the process design, refer to [add records to the table [TabB] to determine the business logic.

 

 

Data operation Client

You can use ASP. NET, Winform, WPF, and silverlight. In this example, use WPF.

 

Add reference to the above WCF Service on the WPF Client

 

Uidesign

Code


Private
Void button#click (object sender, RoutedEventArgs e)

{

WcfServer. ServiceClient ser = new wcfServer. ServiceClient ();

 

WcfServer. TableB row = new wcfServer. TableB ();

Row. ID = ID. Text;

 

Row. RowID = RowID. Text;

 

Row. Value = Value. Text;

 


String message = ser. insertData (row );

 


MessageBox. Show (message );

 

 

}

 

About exception capture, transaction, lock

WF provides these containers. For more information, see [WF4.0 Basics ].

In this example, an exception capture is added to the outermost layer of [flowChar,

 

Effect description

 

 

 

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.