Summary of event on interface type for instance id cannot be delivered.

Source: Internet
Author: User

This workflow exception is often seen: Event "submitevent" on interface type "workflowconsoleapplication2.isalesorderservice" for instance id "8ed729b9-1dd1-46a2-b7ef-fb5a75eeb7fd" cannot be delivered.

According to the MS post, there are many ways that may cause this exception. Therefore, I would like to summarize the problems I have encountered and solutions here.

1. Parameter serialization problems.

1.1 start with an example of a state machine workflow. For example, if you want to process the order status, submit, approve, or reject the workflow, the process ends.

First, let's take a look at the workflow and share it in a simple way. There are three States in total, one handleexternaleventactivity, one custom codeacitactivity, and one setstateactivity in each step.

1.2 start from scratchCode

The order code to process:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace workflowconsoleapplication2
{
Public class salesorder
{
Public int salesorderid {set; get ;}
Public String customername {set; get ;}
Public String productname {set; get ;}
Public int amount {set; get ;}
Public decimal unitprice {set; get ;}
Public decimal totalmoney {set; get ;}
Public int status {set; get ;}
}
}

Service Interface:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. workflow. Activities;

Namespace workflowconsoleapplication2
{
[Externaldataexchange]
Public interface isalesorderservice
{
Event eventhandler <salesorderargs> submitevent;
Event eventhandler <salesorderargs> approvalevent;
Event eventhandler <salesorderargs> rejectevent;
}
}

Local Service Code:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

namespace workflowconsoleapplication2
{< br> public class salesorderservice: isalesorderservice
{< br> public event eventhandler submitevent;
public event eventhandler approvalevent;
public event eventhandler rejectevent;

Public void firesubmitevent (guid instanceid, salesorder)
{< br> If (submitevent! = NULL)
{< br> salesorderargs ARGs = new salesorderargs (instanceid, salesorder);
submitevent (null, argS );
}< BR >}

Public void fireapprovalevent (guid instanceid, salesorder)
{< br> If (approvalevent! = NULL)
{< br> salesorderargs ARGs = new salesorderargs (instanceid, salesorder);
approvalevent (null, argS );
}< BR >}

Public void firerejectevent (guid instanceid, salesorder)
{
If (rejectevent! = NULL)
{
Salesorderargs ARGs = new salesorderargs (instanceid, salesorder );
Rejectevent (null, argS );
}
}
}
}

Event parameter class:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. workflow. Activities;

Namespace workflowconsoleapplication2
{
[Serializable]
Public class salesorderargs: externaldataeventargs
{
Public salesorder {set; get ;}

Public salesorderargs (guid instanceid, salesorder): Base (instanceid)
{
This. salesorder = salesorder;
}
}
}

Workflow class:

Using system;
Using system. componentmodel;
Using system. componentmodel. design;
Using system. collections;
Using system. LINQ;
Using system. workflow. componentmodel. compiler;
Using system. workflow. componentmodel. serialization;
Using system. workflow. componentmodel;
Using system. workflow. componentmodel. design;
Using system. workflow. runtime;
Using system. workflow. Activities;
Using system. workflow. Activities. Rules;

Namespace workflowconsoleapplication2
{
Public sealed partial class workflow1: statemachineworkflowactivity
{
Public static dependencyproperty salesorderargsproperty = dependencyproperty. Register ("salesorderargs", typeof (salesorderargs), typeof (workflow1 ));

[Description ("salesorderargs")]
[Category ("salesorderargs category")]
[Browsable (true)]
[Designerserializationvisibility (designerserializationvisibility. Visible)]
Public salesorderargs
{
Get
{
Return (salesorderargs) (base. getvalue (workflow1.salesorderargsproperty )));
}
Set
{
Base. setvalue (workflow1.salesorderargsproperty, value );
}
}

Public workflow1 ()
{
Initializecomponent ();
}

Private void handlesumitinvoked (Object sender, externaldataeventargs E)
{
Console. writeline ("handlesumitinvoked ");
}

Private void handleapprovalinvoked (Object sender, externaldataeventargs E)
{
Console. writeline ("handleapprovalinvoked ");
}

Private void handlerejectinvoked (Object sender, externaldataeventargs E)
{
Console. writeline ("handlerejectinvoked ");
}

}

}

The custom codeactivity class is the same as the other two classes:

Using system;
Using system. componentmodel;
Using system. componentmodel. design;
Using system. collections;
Using system. LINQ;
Using system. workflow. componentmodel;
Using system. workflow. componentmodel. design;
Using system. workflow. componentmodel. compiler;
Using system. workflow. componentmodel. serialization;
Using system. workflow. runtime;
Using system. workflow. Activities;
Using system. workflow. Activities. Rules;

Namespace workflowconsoleapplication2
{
Public partial class submitactivity: Activity
{
Public static dependencyproperty salesorderargsproperty = dependencyproperty. Register ("salesorderargs", typeof (salesorderargs), typeof (submitactivity ));

[Description ("salesorderargs")]
[Category ("salesorderargs category")]
[Browsable (true)]
[Designerserializationvisibility (designerserializationvisibility. Visible)]
Public salesorderargs
{
Get
{
Return (salesorderargs) (base. getvalue (submitactivity. salesorderargsproperty )));
}
Set
{
Base. setvalue (submitactivity. salesorderargsproperty, value );
}
}

Public submitactivity ()
{
Initializecomponent ();
}

Protected override activityexecutionstatus execute (activityexecutioncontext executioncontext)
{
This. salesorderargs. salesorder. Status = 0;
Return base. Execute (executioncontext );
}
}
}

Start the main function:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Threading;
Using system. workflow. runtime;
Using system. workflow. runtime. Hosting;
Using system. workflow. Activities;

Namespace workflowconsoleapplication2
{
Class Program
{
Static void main (string [] ARGs)
{
Using (workflowruntime = new workflowruntime ())
{
Autoresetevent waithandle = new autoresetevent (false );
Workflowruntime. workflowcompleted + = delegate (Object sender, workflowcompletedeventargs e ){
Salesorderargs soargs = (salesorderargs) E. outputparameters ["salesorderargs"];
Console. writeline (soargs. salesorder. salesorderid + soargs. salesorder. customername + soargs. salesorder. productname + "status" + soargs. salesorder. status );
Waithandle. Set ();
};
Workflowruntime. workflowterminated + = delegate (Object sender, workflowterminatedeventargs E)
{
Console. writeline (E. Exception. Message );
Waithandle. Set ();
};

// Create a data exchange service
Externaldataexchangeservice dataservice = new externaldataexchangeservice ();

// Add the data exchange service to the runtime
Workflowruntime. addservice (dataservice );

// Create a local data interface service
Salesorderservice LocalService = new salesorderservice ();

// Add the local data interface service to the Data Exchange Service
Dataservice. addservice (LocalService );

Workflowinstance instance = workflowruntime. createworkflow (typeof (workflowconsoleapplication2.workflow1 ));

Instance. Start ();

Salesorder so = new salesorder () {salesorderid = 100, customername = "Shanghai Automobile Co., Ltd.", productname = "ACM", unitprice = 1200, amount = 10, totalmoney = 12000, status =-1 };

LocalService. firesubmitevent (instance. instanceid, so );

Waithandle. waitone ();
}
}
}
}

1.3 debug and run

The above Code seems impeccable, but an exception occurs when it runs.

Click the View Detail link below:

 

The real problem is: eventargs not serializable.

But looking back at salesorderargs, this class has already set the [serializable] attribute, why is it still wrong? Is it the salesorder class? It does not set serializable, and it is also set.

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace workflowconsoleapplication2
{
[Serializable]
Public class salesorder
{
Public int salesorderid {set; get ;}
Public String customername {set; get ;}
Public String productname {set; get ;}
Public int amount {set; get ;}
Public decimal unitprice {set; get ;}
Public decimal totalmoney {set; get ;}
Public int status {set; get ;}
}
}

Run again, OK, succeeded!

That is to say, as long as the parameters are used in the parameter class, they must be able to be serialized, rather than simply adding a serialization mark to the parameter class.

 

2. Message Queue problems.

If the submit State is skipped in the main function and the approval event is directly triggered, the Code is as follows:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Threading;
Using system. workflow. runtime;
Using system. workflow. runtime. Hosting;
Using system. workflow. Activities;

Namespace workflowconsoleapplication2
{
Class Program
{
Static void main (string [] ARGs)
{
Using (workflowruntime = new workflowruntime ())
{
Autoresetevent waithandle = new autoresetevent (false );
Workflowruntime. workflowcompleted + = delegate (Object sender, workflowcompletedeventargs e ){
Salesorderargs soargs = (salesorderargs) E. outputparameters ["salesorderargs"];
Console. writeline (soargs. salesorder. salesorderid + soargs. salesorder. customername + soargs. salesorder. productname + "status" + soargs. salesorder. status );
Waithandle. Set ();
};
Workflowruntime. workflowterminated + = delegate (Object sender, workflowterminatedeventargs E)
{
Console. writeline (E. Exception. Message );
Waithandle. Set ();
};

// Create a data exchange service
Externaldataexchangeservice dataservice = new externaldataexchangeservice ();

// Add the data exchange service to the runtime
Workflowruntime. addservice (dataservice );

// Create a local data interface service
Salesorderservice LocalService = new salesorderservice ();

// Add the local data interface service to the Data Exchange Service
Dataservice. addservice (LocalService );

Workflowinstance instance = workflowruntime. createworkflow (typeof (workflowconsoleapplication2.workflow1 ));

Instance. Start ();

Salesorder so = new salesorder () {salesorderid = 100, customername = "Shanghai Automobile Co., Ltd.", productname = "ACM", unitprice = 1200, amount = 10, totalmoney = 12000, status =-1 };

// LocalService. firesubmitevent (instance. instanceid, so );
LocalService. fireapprovalevent (instance. instanceid, so );

Waithandle. waitone ();
}
}
}
}

An exception is shown in the following figure:

The real error is as follows:

"Queue 'message Properties
Interface Type: workflowconsoleapplication2.isalesorderservice
Method Name: approvalevent
Correlationvalues:
'Is not enabled.

 

How can this problem be solved? Let's talk about it after lunch!

 

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.