Passing C# object to k2 process instance and to smart object

  • 26 January 2011
  • 4 replies
  • 9 views

Badge +1


Hi,


Am using k2 blackpearl 4.5,


 


We have service layer written in C# and one of our service will be responsible to instantiate a K2 process,and we want to pass our domain model objects (object graph) to the process without passing each property in the object and it's  associated objects separately  ,our target to pass a domain model object to process instance,the to server event which will communicate with our service again to update domain model object.


1st question :


How can we pass such object to k2 process?


2nd question:


Can we also pass an object to smart object as parameter?


 


Thanks



4 replies

Badge +9


At this point K2 does
not work with .NET based complex types in the client API for workflow or SmartObjects, so something like a linked list or typed object graph wont work
as a parameter into workflows or SmartObjects.
 


I would really like to
understand your requirement a little better, but based on the little that’s
posted here and some wild assumptions, I can offer the following:
 


In order to solve that
specific need, I would suggest you serialize your object graph into a XML
structure that you can import the XML defintion into K2 process as a K2
datafield, then you can serialize an instance of the object graph into that XML
structure and pass it into K2 as a XML based complex type. That XML based
complex type is fully understood in the workflows and you can perform all kinds
of mappings in the process from/to elements in the XML document.
 Similarly you can map elements from that XML into  smartobject
properties.
 


BUT – Because a copy
of the data will be loaded into the K2 server memory for every instance of a
new process that’s running, plus if you have multiple destinations and multiple
workslist items that include that data, it could become a data/memory hog over
many process instances and worklist items..  So,  I would rather
recommend following an approach where complex and bigger chunks of data is
carried outside the K2 process instance.
 


Create SmartObjects that represent your object
graph and serialize them into smartobjects that are carried outside the
workflow and you can simply reference them in workflows and work directly with
the smartobjects, that way there is only one central copy of the data that’s
being worked on and you can always be guaranteed its not stale.

Badge +1

Renier , Thanks a lot for your helpful answer,


Would you please advice how can I serialize my objects to SmartObjects ?


Thanks again.


Suhaib

Badge +1

Suhaib,


 


I had a discission around this with Renier yesterday that ended in the response he gave you.


 


So, I wanted to clarify; you wont be able to directly "serialize" the .net types into smartobjects.. you will need to follow a pattern where your wrap them into a smartobject outside the workflow. Similar to how you would build a WCF service around an existing .net type.


 


Alternatively, you can look into our dynamic WCF stack for smartobjects. This will allow you to build a smartobject as your main domain graph opbjects, and then they will be automatically published as WCF endpoints, thus giving you strongly typed .net object representations of smartobjects that you can code against.


 


Koos


 

Badge +9

Hi Suhaib,


 


For more information around our WCF and K2 SmartObject have a look at the following blog: http://k2underground.com/blogs/comingsoon/archive/2011/01/17/k2-web-services-part-1.aspx

Reply