Once upon a time there was a client that wanted to save all of the data that BizTalk dealt with into a table for further research. Now there is another client that has asked for the same request “We want to store the BizTalk XML message into a database”
Since it has come up now twice, I might as well publish to everyone how you do it.
In your orchestration, you have a long running orchestration with an atomic scope.
As a orchestration variables, you define the following:
As a scope variables, you define the following:
The expression shape in your scope, you have the following code:
TempXmlData=InputMsg; StringWriter=new System.IO.StringWriter(); XmlTextWriter=new System.Xml.XmlTextWriter(StringWriter); TempXmlData.WriteTo(XmlTextWriter); Message=StringWriter.ToString();
Now you have the data available to inject into your insert statement that will be sent to the data repository, along with any context data you want to send along with it.
I have received a few questions as to where the StringWriter was. I always thought that there might be a difference between Visual Studio 2003 (when I wrote this) and the later versions of Visual Studio.
I created a test solution again in BizTalk 2009 and found it. If you try to add the references and look in the System you will not find it!
According to the documentation it is in the mscorlib.dll
So if you look in the References, not in the System you will find it: