BizTalk Server Tutorial

BizTalk Server Concepts and Common Errors

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

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
About these ads

January 20, 2011 - Posted by | Orchestrations | , , ,

7 Comments »

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

    Please advice.

    Comment by AMRIT | August 19, 2011 | Reply

    • 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.

      Comment by Shiv | August 19, 2011 | Reply

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

    Comment by Ravindar Thati | June 13, 2011 | Reply

    • Keep checking the Blog for many new posts !!

      Comment by Shiv | June 13, 2011 | Reply

  3. 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 :)

    Comment by Ravindar Thati | June 11, 2011 | Reply

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

      Comment by Shiv | June 11, 2011 | Reply

  4. i love it

    Comment by facebook | February 17, 2011 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 74 other followers

%d bloggers like this: