Can we use Non-Serializable Classes or Types in an Orchestration ?

Posted: January 20, 2011  |  Categories: Orchestrations Uncategorized

Biztalk is entirely Stateless. This is achieved by using Persistence Points. Incase of any failure during the processing of an Orchestration (for eg: power failure or Server Restart etc) BizTalk Server will continue to restart the Orchestration from the Last Persistence Point.

Details about the Persistence points will be Stored in BizTalk SQL Server DataBase by serializing all the data.

Hence Non-Serializable Classes or Types cannot be used directly in Orchestrations.

Don’t worry, we can use them in orchestration with an Atomic Scope.
Because persistence does not happen within an Atomic scope. The persistence point is created only when the scope completes its execution as it’s an All-or-Nothing scope.So, we can use Non – Serializable Classes or Types inside Atomic Scopes in an Orchestration.

Consider the below Sample:

1. Create a new BizTalk Project and add any dummy Schema.

2. Create a new Orchestration and add a receive shape to receive the message of the Type Schema1 which is created in Step1.

3. Create two variables of types System.Xml.XmlDocument and System.Xml.XmlNode

4. Now add an Expression shape to the orchestration and add code to extract a node from the incoming message and assign that to the variable you created in step3.

5. Try to build the solution. You end up with an error as shown below.

Error 1 a non-serializable object type ‘System.Xml.XmlNode xmlnode’ can only be declared within an atomic scope or service.

6. To resolve this, make the following changes to the solution.

     i. Click on the white space of the Orchestration and make the Transaction Type of the Orchestration to Long Running.

     ii. Add a Scope Shape and set the Transaction Type of the Scope to Atomic and move the Expression shape inside the Atomic Scope.

     iii. Move the xmlnode Variable inside the Atomic Scope.

7. Now build the solution. It should work without any errors.

This is just an example. Although this approach is useful, this should be avoided for performance reasons. Alternatives such as XPaths should be considered.

Hope it Helps.

– Shiv

Web Counters
  • i love it

  • shiv, if you find time, can you please explain this topic with some example narration as you did in other posts.

    i found your blog very useful. Keep posting 🙂

    • Thanks Ravindar… I will try to post example soon…

  • Many thanks Shiv,
    you caring a lot for readers like me.
    Thanks for posting the example.

    • Keep checking the Blog for many new posts !!

  • AMRIT

    System.Xml.XmlDocument is also Non-Serializable Object Type, Then why it is not showing the same error for “System.Xml.XmlDocument”.

    Please advice.

    • Thats a good question… It is a special case that the Orchestration Engine gives us…
      This does happen only for XMLDocument and not for any other types…. That too, it happens only for the variables declared inside the Orchestration..

      You should appreciate the fact that all the Messages used in BizTalk derive from XMLDocument and any message can be casted to XMLDocument.

One Platform Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

One Platform - Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

One Platform - Operations, Monitoring and Analytics Software
ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

Back to Top