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:



Categories: BizTalk

17 replies

  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. Thanks for the tip!

  4. Fantastic!. Thanks for blogging the issue. Absolute life saver🙂

  5. Beautiful!!!!!
    Saved my day!!!

  6. Thank you so much, this post saved me a lot of pain!

  7. Add me to the list of thank yous And thanks also for redirecting me over here from the MSDN Forum.

  8. Saved my day ! Thx !

  9. 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?

  10. 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?

  11. 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!

  12. Great idea . . . Thank you very much !

  13. Thanx, just what I needed

  14. Ha, such a simple gotcha, but thanks for writing it up! Saved me a bit of time.

  15. 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…

Trackbacks

  1. .debug » Initializing Correlations in a Loop

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

%d bloggers like this: