Ext.: http://www.cnblogs.com/carysun/archive/2009/01/11/receiveactivity.html
If you have ever been in charge of developing an ERP system or OA system, the workflow will not be a stranger to you. A workflow (Workflow) is an abstraction, generalization, and description of the business rules between a workflow and its various operational steps. The main problem for a workflow to solve is to automate the delivery of documents, information, or tasks between multiple participants, using a computer, and by a predetermined rule, to achieve a business goal. In view of this, Microsoft published WF,WCF on. NET 3.0, as well as WCS (authentication Solution), WPF (for development of the presentation layer). WF is the key to solving the core issues of the enterprise, and WF makes it easy to implement development according to business logic, and then publish WF as a Web service so that the client and service-to-server communication is no longer affected by the development language, and the Web service makes it easy to invoke WF for business operations.
Here is an example of a simple order entry system that shows you how to publish a workflow workflow as a Web service.
To implement a persistent workflow, first create a local database with the utility sqlcmd, open a Command Prompt window, enter
Sqlcom-s localhost/sqlexprress-e-Q "CREATE Database Workflowpersistence"
Then open the folder
/microsoft.net/framework/v3.0/windows Workflow Foundation/sql/[lauguage]
There are 2 script files inside.
Sqlpersistenceservice_schema.sql, Sqlpersistenceservice_logic.sql
The database can be created successfully by running this script file on the database workflowpersistence.
Example Description: When the customer joins the order for the first time, the Start method is called through the Web service to create a new workflow object instance, and the AddOrder method can be called multiple times to add the order, and the Workflow object instance is in a persisted state before the order is submitted. When the server is idle, the data about the workflow object is stored in the Workflowpersitence database, which can effectively reduce the pressure on the server cache. After the last call to the end method to submit the order, the workflow workflow object ends and the data for the workflow object is deleted in the database.
First, define an order class, and don't forget to add serializable serialization properties to the object
[Serializable]
public class Order
{...}
Develop an operation class for Order OrderManager, which includes a method AddOrder, when each order is added, the method returns the ID of the newly added order
public class OrderManager
{
public int AddOrder (order order)
{..........}
}
Now for this example we will first develop an interface Iservice_t1,start method means to start this workflow workflow, and end indicates that this workflow is completed
Namespace Microsoft.iservice
{
public interface Iservice_t1
{
void Start ();
int AddOrder (order order);
void End ();
}
}
Is the full view of this workflow, we first use webServiceInputActivity1 to start the service
Here, set the Isactivating property of WebServiceInputActivity1 to True, which means that this Workflow object instance is activated with this activity, The InterfaceType is then set to Microsoft.IService.IService_T1 and the MethodName is set to start, and the Workflow object instance is activated when the client invokes the Start method.
Then set the whileactivity loop condition (this. Isrepeated==true), which means that if the value of isrepeated is true, whileactivity can run continuously, the workflow is in a persisted state
Now set up 2 event-driven activities for ListenActivity1, in the event-driven activity on the left, add WebServiceInputActivity2, CodeActivity1, webServiceOutputActivity1 respectively. Set the InterfaceType of the WebServiceInputActivity2 to Microsoft.IService.IService_T1, and then set the MethodName to AddOrder, Bind the parameter order in the AddOrder method to the parameter in this workflow object _order (refer to the full code) so that the AddOrder method can be mobilized by WebServiceInputActivity2. Then add the operation code in the Codeactivity_executecode method of the codeactivity.
Finally, the Inputactivityname property is set to WebServiceInputActivity2 by the WebServiceOutputActivity1 end operation, and the variable ID is returnvalue bound. This allows the system to get the return value (int) ID of the AddOrder method after the order is inserted.
Now, you can insert a webServiceInputActivity3 in the event-driven activity on the right, set InterfaceType to Microsoft.IService.IService_T1, Set the MethodName to end, and then add the handling method of event inputreceived webserviceinputactivity3_inputreceived, set the Isrepeate property to False by this method, This lets you mobilize this activity to finally loop and end the workflow.
This is the complete code for the workflow:
Namespace Microsoft.workflows
{
public sealed partial class workflow:sequentialworkflowactivity
{
Public order _order ;
Public int id ;
Public bool isrepeate = true ;
Public Workflow2 ()
{
InitializeComponent ();
//Do this when the AddOrder method is called , insert order by OrderManager object, last return value OrderID Assign to this workflow parameter ID
private void codeActivity1_ExecuteCode (object sender, EventArgs e)
{
OrderManager ordermanager=new OrderManager ();
int Orderid=ordermanager.addorder (order);
This.id=orderid;
}
When the webServiceInputActivity3 activity is called, the value of Isrepeate is set to false, which terminates the loop to the bundle of this workflow object.
private void Webserviceinputactivity3_inputreceived (object sender, EventArgs e)
{
Isrepeate = false;
}
}
}
At this time, right click on this "project", select "This workflow as a Web publishing", get the following ASMX file
Microsoft.Workflows.Workflow2_WebService.asmx
<% @WebService class= "Microsoft.Workflows.Workflow2_WebService"%>
Add a configuration file
<?xml version= "1.0"?>
<configuration>
<configSections>
<section name= "WorkflowRuntime" type= "System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35 "/>
</configSections>
<workflowruntime name= "Workflowservicecontainer" >
<Services>
<add type= "System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, version= 3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35 "/>
<add type= "System.Workflow.Runtime.Hosting.DefaultWorkflowCommitWorkBatchService, System.Workflow.Runtime, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35 "/>
<add type= "System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, version= 3.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35 "unloadonidle=" true "loadintervalseconds=" 5 " connectionstring= "Data source=leslie-pc;initial catalog=workflowpersistence;integrated Security=True"/>
This is to add the SQL database persistence service for workflow, because this configuration is necessary if you are testing a persisted workflow.
</Services>
</WorkflowRuntime>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug= "true"/>
<authentication mode= "Windows"/>
<add type= "System.Workflow.Runtime.Hosting.WorkflowWebHostingModule, System.Workflow.Runtime, version=3.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35 "name=" Workflowhost "/>
</system.web>
</configuration>
Call the Start method to start workflow, and then you can call the AddOrder method directly, you will find that unlike the previous instance, in the previous example, each instance is allowed to be called only once, and when the page has not been reloaded multiple calls will appear with an error prompt. In this case, AddOrder can be called multiple times and run normally, which proves that the instance object of the workflow you are invoking is already a persisted workflow and that the workflow object can be running when you do not call end service.
Finally, you can call the end method to end the operation, and when the operation is finished, then call AddOrder, and the system will display an error:
System.InvalidOperationException: The workflow with ID "3a8b9688-fb3f-4a10-bb84-6bf99c30119a" is not found in the state persistence store.
To summarize, by persisting the development of a service flow, you can maintain the active state of the workflow instance, so that you can call each other through multiple Web services. Using this technology to implement workflow-based applications, you can expose them through a Web service to clients and maintain their working state.
Web services and WF can invoke each other, and in these two chapters we show you how to publish a workflow as a Web service, and the next chapter will introduce you to calling Web services through Invokewebserviceworkflow in WF.
Interested in net system development friends, please join QQ Group: NET Technology Development Alliance 595,573,291 Discussion
WF Workflow Technology Insider-invoke workflow workflow via Web service (base instance)
WF Workflow Technology Insider-invoke workflow workflow via Web service (develop persisted workflow)
WF Workflow Technology Insider-invoking Web services in a workflow workflow through Invokewebserviceactivity
WF Workflow Technology Insider--WF and WCF call each other (using receiveactivity to publish WF as WCF)
Turn: WF Workflow Technology Insider-invoke workflow workflow via Web service (develop persisted workflow)