WF event-driven (2)

Source: Internet
Author: User

I introduced the first part of wf4's new event-driven workflow design. We can summarize several key points.

1. The event mechanism of wf4 is revolutionary and different from that of WF3. WF3 is based on the externaldataexchange service. Wf4 is based on WCF. This design is much easier for developers.

2. In WF3, the so-called eventdriven activity is used, while in wf4, the activity like receive is used. In fact, this clue can be seen from the WF 3.5.

3. If you need to listen for events, you cannot use workflowinvoker or workflowapplication to start the process. Instead, you must use workflowservicehost to start the listener. (There is a fundamental difference here. workflowservicehost only starts listening and does not create a workflow instance immediately .)

 

In the previous article, we talked about how to receive client requests and make responses. This kind of response is limited to printing related messages on the server.

But obviously this is not enough. We have created process integration. At least we want to notify the client of the latest number of the process. So, how should we design it?

Code of this article, which can be downloaded here

 

1. Modify WorkFlow Design

Wf4 has taken into consideration this requirement. we can select the receive activity and find create sendreply In the right-click menu.

Click this menu and a prompt is displayed.

 

We can choose to paste it anywhere, such

Note that a variable named _ handler1 will be added at this time, and its type is correlationhandler. We will introduce this variable in detail later. Here we will not pay attention to its details.

 

The pasted activity is automatically associated with the previous receive activity.

So what data should we send to users? Click content on the activity.

Bind the message data to our previous ticketid variable and set the type to int 32.

 

In this way, we have designed the process. Recompile it.

 

2. regenerate the client code class

The process has changed. Generally, the client proxy class also needs to change. Start the server program first.

Confirm that the following results are displayed in the browser.

Generate client code file

 

3. Modify the client

Add the generated documentreviewworkflow. CS file to the client project and replace the original file.

No need to add output. config here, because the content of this file has not changed.

The modify window is as follows. A ListBox is added.

 

Modify the Code as follows:

        private void btCreate_Click(object sender, EventArgs e)        {            var proxy = new DocumentReviewClient();            var result = proxy.CreateTicket();            lstTickets.Items.Add(result);        }

 

Note that the createticket method returns the value (Int ?), In the previous article, it does not return a value, which is void.

 

4. debug the program

Press the F5 key for debugging. If you click "create process" multiple times in the window, what will happen?

Not only does the server have message output, but we can also see a ticketid list on the client.

 

Code of this article, which can be downloaded here

 

Next, we will complete the example of this process, and we will add the manager approval event. With this example, you can understand how to design an event-driven process.

I introduced the first part of wf4's new event-driven workflow design. We can summarize several key points.

1. The event mechanism of wf4 is revolutionary and different from that of WF3. WF3 is based on the externaldataexchange service. Wf4 is based on WCF. This design is much easier for developers.

2. In WF3, the so-called eventdriven activity is used, while in wf4, the activity like receive is used. In fact, this clue can be seen from the WF 3.5.

3. If you need to listen for events, you cannot use workflowinvoker or workflowapplication to start the process. Instead, you must use workflowservicehost to start the listener. (There is a fundamental difference here. workflowservicehost only starts listening and does not create a workflow instance immediately .)

 

In the previous article, we talked about how to receive client requests and make responses. This kind of response is limited to printing related messages on the server.

But obviously this is not enough. We have created process integration. At least we want to notify the client of the latest number of the process. So, how should we design it?

Code of this article, which can be downloaded here

 

1. Modify WorkFlow Design

Wf4 has taken into consideration this requirement. we can select the receive activity and find create sendreply In the right-click menu.

Click this menu and a prompt is displayed.

 

We can choose to paste it anywhere, such

Note that a variable named _ handler1 will be added at this time, and its type is correlationhandler. We will introduce this variable in detail later. Here we will not pay attention to its details.

 

The pasted activity is automatically associated with the previous receive activity.

So what data should we send to users? Click content on the activity.

Bind the message data to our previous ticketid variable and set the type to int 32.

 

In this way, we have designed the process. Recompile it.

 

2. regenerate the client code class

The process has changed. Generally, the client proxy class also needs to change. Start the server program first.

Confirm that the following results are displayed in the browser.

Generate client code file

 

3. Modify the client

Add the generated documentreviewworkflow. CS file to the client project and replace the original file.

No need to add output. config here, because the content of this file has not changed.

The modify window is as follows. A ListBox is added.

 

Modify the Code as follows:

        private void btCreate_Click(object sender, EventArgs e)        {            var proxy = new DocumentReviewClient();            var result = proxy.CreateTicket();            lstTickets.Items.Add(result);        }

 

Note that the createticket method returns the value (Int ?), In the previous article, it does not return a value, which is void.

 

4. debug the program

Press the F5 key for debugging. If you click "create process" multiple times in the window, what will happen?

Not only does the server have message output, but we can also see a ticketid list on the client.

 

Code of this article, which can be downloaded here

 

Next, we will complete the example of this process, and we will add the manager approval event. With this example, you can understand how to design an event-driven process.

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.