Rules (with static C# routines, such as PolicyChaining, or C# code that adds nodes to the XML), are working fine on XP but not on 2003 (or working on machine and not another). For example, we have a condition of 1=1, which should always fire, but if a static C# routine is found in the actions, then the rules does not fire.

See Richard Seroter’s blog. There is a registry setting that must be set to allow business rules to call a static C# method.

Also note, if you change a C# program, and even re-GAC it, to get the Business Rule Composer to “see” the changes, you have to close and re-open the Business Rule Composer if you are using the test policy feature.

If you download the Policy-Chaining sample for BizTalk, it has an automated way of updating the registry setting. In it’s setup.bat.

@ECHO Setting the StaticSupport registry key to ONE
@REGEDIT /s AddStaticSupport.reg

The AddStaticSupport.reg include the following statements:


System.Net.WebException: Unable to connect to remote server No connection could be made because the target machine actively refused it

For me, this was an easy one, IIS was down.

Other ideas:
1) Check app.exe.config and make sure URL is corect
2) Make sure machine name is correct http://xxxxxxxx or http://localhost

BizTalk Server 2006 is not available or configured. Verify BizTalk Server 2006 on server xxxxx using management database BizTalkMgmtDb is accessible and configured with a compatible version.

This frequently occurs in the company I’m working. All development is done on VMWare virtual machines, when the systems guys do a backup of VMWare “LabManager”, the virtual machine are shutdown and then restarted. For some odd reason, after the restart, SQL frequently does not start (even though it is set as “automatic start”.

To solve the problem, go to System Services, and if SQL is not started, then start it.

How to use TextWriter to file.

            string strOutFileName = @"c:YourDirYourFile.xml";
   ... assumes you have an xmlDoc somewhere
            System.Xml.XmlTextWriter tw = new XmlTextWriter(strOutFileName, System.Text.Encoding.ASCII);

How to initialize an array of objects in C#. Often, we write C# test harnesses to populate some test data based on an object structure (which was ultimately created from an xml structure).

            svcref1.WiringLoanReq req =
                new TMAC.Wiring.UnitTest.CallPublishedOrch.svcref1.WiringLoanReq();
            svcref1.WiringLoanResp resp =
                new TMAC.Wiring.UnitTest.CallPublishedOrch.svcref1.WiringLoanResp();
            svcref1.WiringLoan loan1 =
                new TMAC.Wiring.UnitTest.CallPublishedOrch.svcref1.WiringLoan();
            svcref1.WiringLoan loan2 =
                new TMAC.Wiring.UnitTest.CallPublishedOrch.svcref1.WiringLoan();

            loan1.CadenceLoanId = "0012341234";
            loan1.CadenceLoanId = "0012341235";

            req.WiringLoans = new TMAC.Wiring.UnitTest.CallPublishedOrch.svcref1.WiringLoan[2];
            req.WiringLoans[0] = loan1;
            req.WiringLoans[1] = loan2;

// call the web service
 resp = client.getWiringRequest(req);

How to add an node to an XML Document (via a C# helper that can be called in an expression shape from an orchestration).

First example (uses AppendChild):

        public static XmlDocument AddExceptionNodeToTMXML(XmlDocument TMXMLDocIn, Exception ex)
            // three import fields in System.Exception are ex.Message, ex.StackTrace, ex.Source
            // then there is an Ex.InnerException

            XmlDocument xmlDocNewTMXML = new XmlDocument();
            xmlDocNewTMXML.LoadXml(TMXMLDocIn.OuterXml);  // make sure we don't update the original TMXMLDocIn

            string errMessage = "";
            string errSource = "";
            string errStackTrace = "";
            string xml;

            if (ex.InnerException == null)
                // if not nested exceptions, do not number them.
                errMessage = ex.Message;
                errStackTrace = ex.StackTrace;
                errSource = ex.Source;
                // loop through all the nested exceptions and concatenate them into single long string variables
                System.Exception innerEx = ex;
                int loopCounter = 0;
                while (innerEx != null)
                    // number the nested exceptions
                    string separator = "";
                    if (loopCounter &gt; 1)
                        separator = ";";

                    errMessage = errMessage + separator + "n     Ex:" + loopCounter + ") " + innerEx.Message;
                    errStackTrace = errStackTrace + separator + "n     Ex:" + loopCounter + ") " + innerEx.StackTrace;
                    errSource = errSource + separator + "n     Ex:" + loopCounter + ") " + innerEx.Source;
                    innerEx = innerEx.InnerException;



            // Added CDATA clauses below, because the err fields may have
            // ampersand, less-than, greater than, or other problem characters that cause the xmlDoc.Load to  fail. 
            xml =
                    @"&lt;exs:Exceptions xmlns:exs='http://YourSchemaNamespace.Exceptions'&gt;" +
                    "&lt;ex:Exception index='1' id='1' type='' xmlns:ex='http://YourSchemaNamespace.Exception'&gt;" +
                    "  &lt;messageText&gt;&lt;![CDATA[" + errMessage + "]]&gt;&lt;/messageText&gt;" +
                    "  &lt;source&gt;&lt;![CDATA[" + errSource + "]]&gt;&lt;/source&gt;" +
                    "  &lt;stackTrace&gt;&lt;![CDATA[" + errStackTrace + "]]&gt;&lt;/stackTrace&gt;" +
                    "&lt;/ex:Exception&gt;" +

            XmlDocument exceptionXML = new XmlDocument();

            string strXPathRoot = "/*[local-name()='TMXML' and namespace-uri()='http://YourSchemaNamespace.MainSchema']";
            XmlNode nodeTMXML = xmlDocNewTMXML.SelectSingleNode(strXPathRoot);

            string strExXPathRoot = "/*[local-name()='Exceptions' and namespace-uri()='http://YourSchemaNamespace.Exceptions']";
            XmlNode nodeExceptions = exceptionXML.SelectSingleNode(strExXPathRoot);

            nodeTMXML.AppendChild(xmlDocNewTMXML.ImportNode(nodeExceptions, true));

            return xmlDocNewTMXML;



Second example (uses CreateElement)


	// This can be called from a BusinessRule which passes a TypedXmlDocument
	// instead of a normal XmlDocument
	public static void AddItineraryStep(TypedXmlDocument txd, string stepName, string activityPolicy)

                  // can we find the XPath  indicate d?
                  string strXPathRoot = "//*[local-name()='ItinerarySteps']";
                  XmlNode node = LocateXPath(txd, strXPathRoot);
                  if (null == node)
                      throw new Exception("AddItineraryStep: XPath did not return a valid node, XPath=" +
                          strXPathRoot + "  XML=" + txd.Document.OuterXml);

                  // determine the root node for the document
                  // if the XPath selects the TXD, it will have no root if it is an XmlDocument
                  // in that case, simply use the document from the TXD
                  XmlDocument root = node.OwnerDocument;
                  if (null == root)
                        // if the XPath selects the TXD, it may
                        // so fix accordingly
                        root = txd.Document as XmlDocument;
                        if (null == root) return;

                  // create a new node and add it in
                  string nodeName = "ItineraryStep";
                  XmlElement newNode = root.CreateElement(nodeName);

                  // Not sure why ImportNode not available. Seems like it would be easier
                  //node.AppendChild(txd.Document.ImportNode(nodeItineraryStep, true));

                  //strXPathRoot = "/*[local-name()='Header']/*[local-name()='Itinerary']/*[local-name()='ItineraryStep']";
                  strXPathRoot = "//*[local-name()='ItineraryStep']";
                  node = LocateXPath(txd, strXPathRoot);
                  if (null == node)
                      throw new Exception("AddItineraryItem: XPath did not return a valid node, XPath=" +
                          strXPathRoot + "  XML=" + txd.Document.OuterXml);

                  XmlElement newSubNode;

                  nodeName = "name";
                  newSubNode = root.CreateElement(nodeName);
                  newSubNode.InnerText = stepName;

                  nodeName = "status";
                  newSubNode = root.CreateElement(nodeName);
                  newSubNode.InnerText = "PENDING";

                  nodeName = "errorType";
                  newSubNode = root.CreateElement(nodeName);
                  // leave value to empty-string (no need to set InnerText)

                  nodeName = "activityPolicy";
                  newSubNode = root.CreateElement(nodeName);
                  newSubNode.InnerText = activityPolicy;


        internal static XmlNode LocateXPath(TypedXmlDocument txd, string xPath)
            // does the TXD contain a node?
            XmlNode parent = txd.Document;
            if (null == parent) return null;

            // is there an XPath specified? if not, return the parent
            if ((xPath == null) || (xPath == string.Empty)) return parent;

            // return the first node that the XPath points to
            return parent.SelectSingleNode(xPath, txd.NamespaceManager);