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:

Comments

17 responses to “Initializing BizTalk Correlation Sets In a Loop (Thanks Tomas!)”

  1. Tomas Restrepo Avatar

    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. […] guy has described the elegant way to do […]

  3. Philip Skov Knudsen Avatar
    Philip Skov Knudsen

    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…

  4. Brad Avatar
    Brad

    Thanks for the tip!

  5. Zeeshan Avatar

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

  6. Praseeth Avatar
    Praseeth

    Beautiful!!!!!
    Saved my day!!!

  7. Mark Avatar

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

  8. Matt Smith Avatar
    Matt Smith

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

  9. Matthew Avatar
    Matthew

    Saved my day ! Thx !

  10. Tushar Dabhade Avatar
    Tushar Dabhade

    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?

  11. Richard Seroter Avatar

    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?

  12. Anita Avatar

    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!

  13. Junaid Avatar

    Great idea . . . Thank you very much !

  14. Jeroen Avatar
    Jeroen

    Thanx, just what I needed

  15. rspice Avatar
    rspice

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

  16. Esa Avatar
    Esa

    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 comment

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