Mittwoch, 20. April 2011

Message creation in orchestrations “from scratch”

In some cases it is useful to create a BizTalk message without mapping it from another message.


If you have a Message Assign shape and you access a distinguished field on the message like


msgSample.ErrorCode = “4711”;


without a Transform shape in advance you get the following error during compiling


Message part has not been initialized in construct statement


This is because the xml message has not been initialized. For some reason it is necessary that the “empty” message needs to already contain a tag for the field ErrorCode.


To avoid this issue, you would add a Transform shape with a map, where the root node of the source schema is linked with the field ErrorCode on the target schema. Without mapping you need to construct this manually. For me, the following worked well:


I added a variable with name tempXml of type System.Xml.XmlDocument to the orchestration. In an expression shape I loaded an XML template and constructed the message.


tempXml = new System.Xml.XmlDocument();
tempXml.LoadXml(“…”);

construct msgSample
{
msgSample = tempXml;
msgSample.ErrorCode = “4711”;
}


The XML template for LoadXml can be generated on the schema file in Solution Explorer.


Another way could be to call custom code like


construct msgSample
{
msgSample = CustomClass.CustomMethod(...);
msgSample.ErrorCode = “4711”;
}


The method should be declared in a separate c# project as follows


public class CustomClass
{
public static XmlDocument CustomMethod(...)
{
...
}

}

BizTalk Server 2010 Feature Pack

Slightly after the release of BizTalk Server 2010 a Feature Pack has been released. This feature pack contains only one feature which is named BizTalk Server 2010 AppFabric Connect for Services. It provides for bridging the capabilities of BizTalk Server and Windows Azure AppFabric thereby enabling enterprises to extend the reach of their on-premise Line of Business (LOB) systems and BizTalk applications to cloud.


Download

Samstag, 22. Januar 2011

CU3 for BizTalk Server 2006 R2 SP1

In the end of 2010 Microsoft released the third cumulative update package for BizTalk Server 2006 Service Pack 1.

KB2286501 Download

You do not need prior update packages to apply this. If you are not affected by any problems Microsoft recommends to wait for the next Service Pack release.

CU1 for BizTalk Server 2009

A few days ago, Microsoft released the first cumulative update package for BizTalk Server 2009

KB2429050 Download

If you are not affected by any problems Microsoft recommends to wait for the next Service Pack release.

Freitag, 22. Oktober 2010

Replace Text in Streams

Today, I thought about replacing text in streams. I noticed that .NET 4 provides methods for type

String
to replace some text, but no methods for type
Stream
I found a way by converting the stream to a string in a first step and by replacing text in a second step.
new StreamReader(i).ReadToEnd().Replace("old text", "new text")

For a lot of cases this is alright and there is nothing to worry about. But if the source is a huge amount of data and I do not want to hold it in memory all the time, things get tricky. For these cases I wrote a simple method called

ReplaceTextInStream

The method gets four arguments: an input stream, an output stream, a string with a pattern to search for and a string with the replacement value. If one argument is null, a ArgumentNullException is thrown. Here is the code: Enjoy!

public static void ReplaceTextInStream(Stream input, Stream output, string pattern, string replacement) 
{
    if (input == null)
    {
        throw new ArgumentNullException("input");
    }
    if (output == null)
    {
        throw new ArgumentNullException("output");
    }
    if (pattern == null)
    {
        throw new ArgumentNullException("pattern");
    }
    if (replacement == null)
    {
        throw new ArgumentNullException("replacement");
    }
    StreamReader r = new StreamReader(input);
    StreamWriter w = new StreamWriter(output);
    // Input and Pattern are empty => Output = Replacement
    if(input.Length == 0 && pattern.Length == 0)
    {
        w.Write(replacement);
    }
    // Pattern is empty => Output = Input
    if (input.Length != 0 && pattern.Length == 0)
    {
        while (!r.EndOfStream)
        {
            w.Write((char)r.Read());
        }
    }
    // Init empty Stack
    List<char> stack = new List<char>();
    // Loop over input characters
    while (!r.EndOfStream)
    {
        // Read next input character
        char c = (char)r.Read();
        // Compare characters
        if (pattern[stack.Count] == c)
        {
            // Match => Put it on Stack
            stack.Add(c);
            // Match complete?
            if (stack.Count == pattern.Length)
            {
                // Write Replacement and clear Stack
                w.Write(replacement);
                stack.Clear();
            }
        }
        else
        {
            // No Macth => Stack filled?
            if (stack.Count != 0)
            {
                // Write and Clear Stack
                foreach (var tc in stack)
                {
                    w.Write(tc);
                }
                stack.Clear();
            }
            // Copy current character
            w.Write(c);
        }
    }
    // After Loop: Stack filled?
    if (stack.Count != 0)
    {
        // Write and Clear Stack
        foreach (var tc in stack)
        {
            w.Write(tc);
        }
        stack.Clear();
    }
    w.Flush();
}

Useful .NET Tools

Here is a list of tools I use for .NET development. Each of them saves me a lot of time.

JetBrains ReSharper
Resharper is an extension by Jetbrain for Visual Studio, which improves the development experience. ReSharper executes solution-wide static code analysis, error detection on-the-fly, without the need to compile, provides additional features for error correction, code completion, navigation, search, refactorings, syntax highlighting, formatting, code generation and optimization among other features.
Download

redgate .NET Reflector
.NET Reflector is a class browser and analysis tool for .NET. It allows you to navigate, search, disassemble and analyze .NET components.
Download

WinMerge
WinMerge is a powerful differencing and merging tool. It’s Open Source. WinMerge can compare folders and files, presenting differences in a visual text format that is easy to understand and handle.
Download

Instant SQL Formatter
Online tool for formatting SQL statements. Supported database types are MSSQL, Oracle, DB2, MySQL and others
Link

C# Regular Expression Helper
Litte tool for testing regular expressions
Download

XPath Tester
Little tool for testing XPath statements
Download

Freitag, 8. Oktober 2010

Resumed Orchestration Instances are not processed

Today, in BizTalk 2009 I runned into the following problem: I resumed orchestration instances. They get a processing server, but they are not processed. The orchestration debugger showed, that nothing has happened. Restarting host instance does not change anyhting. Running the MsgBoxViewer showed a MsgBox database integrity problem. The text said

Missing Restart Msg in Spool table (can prevent some svc instances to be resumed, terminated or suspended) !!

Missing Suspend Msg in Spool table (can prevent some svc instances to be resumed, terminated or suspended) !!

Missing Terminate Msg in Spool table (can prevent some svc instances to be resumed, terminated or suspended) !!

Missing ResumeInDebugMode Msg in Spool table (can prevent some svc instances to be resumed, terminated or suspended) !!

Following the hint to run the Terminator tool is not necessary. Just do THIS. Afterwards, restart the host instances. All running, but not processed orchestration instances are processed.