Initializing BizTalk Correlation Sets In a Loop (Thanks Tomas!)

You ever find that newsgroup post on a technical subject that absolutely saves the day? One of my projects has an orchestration that calls a web service. I call this service in a “loop” because if a call fails (for “business” or “technical” reasons), it may need to retried. So, until I set a “ProcessComplete” flag, the loop continues.

That said, if I DO get an error, I send the message out for review. If I don’t get a response within an hour, I auto-retry the service again. This is done with a transactional scope (long-running) and a timeout. So naturally I have to use correlation to send a message out of my orchestration, and potentially receive a message back. However, after setting this up the first time, I got a
Correlation set may be initialized only once
error. This makes sense since I had a global correlation set, and was potentially initializing it over and over in a loop. After staring at my computer for 4 minutes thinking, I did a quick search online and came across a newsgroup post where my new best friend, Tomas Restrepo, reminded me that a *scope* can have its own local correlations sets.

Sure enough, after moving the correlation set to the local scope, everything compiled fine.

Technorati Tags:

Author: Richard Seroter

Richard Seroter is Director of Outbound Product Management at Google Cloud, with a masterโ€™s degree in Engineering from the University of Colorado. Heโ€™s also an instructor at Pluralsight, a frequent public speaker, the author of multiple books on software design and development, plus former editor and former 12-time Microsoft MVP for cloud. As Director of Outbound Product Management at Google Cloud, Richard leads a team focused on products that help teams build and run modern software. Richard maintains a regularly updated blog on topics of architecture and solution design and can be found on Twitter as @rseroter.

17 thoughts

  1. Hey, I’m glad I was able to help ๐Ÿ™‚
    What’s funny is that I found out about this while trying to do something pretty similar to your own stuff (i.e. manually handling retries in a webservice call) ๐Ÿ™‚

  2. Well if Thomas is your new best friend, you’re *my* new best friend, since your blog came up when I googled ๐Ÿ™‚

    Thanks for writing it out, for me to find. A scope – of course…

  3. Have you tried correlation with 2 different message. I am using your latest book SOA patterns but couldn’t find any note on that.
    Here is my problem…I am inserting a XML message in a db table via WCF sql send adapter (store procedure pInsertMsg). I am waiting for external process to update that message. I use WCF SQL recieve adapter (store procedure pGetMsg) to get that message back to my orchestration. I cannot correlate this message because of their different MessageType and root. Moreover the get has TypedPolling so it create a different xsd.

    Can you help?

  4. Thushar, the correlation shouldn’t be dependent on a different message type/root as long as you promote the fields in all the source schemas to the same property in the property schema. Have you already done that?

  5. I can not belive how simple the solution to my problem was. I am quite new to BizTalk-development and I have been struggeling with this issue for for more than a day. Thank you for posting this!

  6. Thanks a lot! Saved my day – incredible that I haven’t needed to do this earlier although I’ve been mostly working with BizTalk for the last 12 years…

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.