amWong

Hello,

I want create a workflow with custom activity by only-xoml, and the activity was defined as followed.

MyActivity's Definition

public partial class MyActivity: SequenceActivity
{
public MyActivity()
{
InitializeComponent();
}
}

Then I wrote a xoml file like this.

<SequentialWorkflowActivity x:Name="MyWorkflow." xmlns:ns0="clr-namespace:MyNamespace" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<ns0:MyActivity x:Name="myActivity1" />
<DelayActivity TimeoutDuration="00:00:00" x:Name="delayActivity1" />
</SequentialWorkflowActivity>

But when I create the workflow with code followed,I caught an error.Is there some further setting or requirement if I want to do that.Is the custom activity only supported in compiled way Thanks.

Code to CreateWorkFlow

using (XmlReader xr = XmlReader.Create("../../WorkflowTest.xml"))
{
WorkflowInstance instance = workflowRuntime.CreateWorkflow(xr);
instance.Start();
}

{error 347: Could not deserialize object. The type 'MyNamespace.MyActivity' could not be resolved.}



Re: Windows Workflow Foundation Create Workflow by only-xoml

Windie Chai

Hi!

try this.


TypeProvider typeProvider = new TypeProvider(workflowRuntime);
typeProvider.AddAssembly(Assembly.GetExecutingAssembly());
runtime.AddService(typeProvider);

using(XmlReader xr.........





Re: Windows Workflow Foundation Create Workflow by only-xoml

amWong

Hi Windie Chai,

Thank you for your answer.

I read the definition and description of "WorkflowRuntime.AddService(object)" at msdn.I found the serivce object must be inherited from WorkflowRuntimeService but the TypeProvider not.Then the TypeProvider object can also be get and set,but the WorkflowRuntime will only be a simple service container.

Am I right Or I didn't understand your answer.Could you explain it clearly Thank you very munch!





Re: Windows Workflow Foundation Create Workflow by only-xoml

Windie Chai

Hi,

When we activate workflow instance from XOML, we should specify an assembly that containing our custom activity.

So we need to use a TypeProvider service. This service holds references to assemblies needed for workflow activation.

And I think your custom activity should be [Serializable()].





Re: Windows Workflow Foundation Create Workflow by only-xoml

amWong

Hi,

I added [Serializable()] to MyActivity and added the TypeProvider Service to WorkflowRuntime.But the same error raised.

Could you show me a successful sample Thank you very much!





Re: Windows Workflow Foundation Create Workflow by only-xoml

Windie Chai

Hi,

I have done some test.

Code of host:

Code Snippet

TypeProvider typeProvider = new TypeProvider(workflowRuntime);
typeProvider.AddAssembly(Assembly.LoadFrom("MyActivity.dll"));
workflowRuntime.AddService(typeProvider);

using (XmlReader xr = XmlReader.Create("../../Workflow1.xoml"))
{
WorkflowInstance instance = workflowRuntime.CreateWorkflow(xr);
instance.Start();
Console.Read();
}

Code of Workflow XOML:

Code Snippet
<SequentialWorkflowActivity
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflowhttp://schemas.microsoft.com/winfx/2006/xaml/workflow">http://schemas.microsoft.com/winfx/2006/xaml/workflow</A< A>>"
xmlns:ws="clr-namespace:MyActivity;assembly=MyActivity" >
<ws:MyActivity Output="this is a demo."/>
</SequentialWorkflowActivity>

My custom activity is in another project. So I load assembly by the assembly filename.

If you like , tell me your email address, I can send the demo to you.





Re: Windows Workflow Foundation Create Workflow by only-xoml

amWong

Hi,

My email is wangchao8383@msn.com. Please send your demo to me, so that I can compare them cleary.Thank you very much!





Re: Windows Workflow Foundation Create Workflow by only-xoml

Windie Chai

send to you .





Re: Windows Workflow Foundation Create Workflow by only-xoml

amWong

Thank you Windie Chai.I found the reason:

<SequentialWorkflowActivity x:Name="MyWorkflow." xmlns:ns0="clr-namespace:MyNamespace;assembly=MyAssembly" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">
<ns0:MyActivity x:Name="myActivity1" />
<DelayActivity TimeoutDuration="00:00:00" x:Name="delayActivity1" />
</SequentialWorkflowActivity>

As the highlighted code show,the "assembly" is always required even the same assembly.Thank you for your demo!Thank you!