Add Namespace to Inbound BizTalk Messages

Did you know that BizTalk Server has a hidden pipeline component that can add namespaces to inbound documents?

Often, you’ll find that you’re retrieving XML data from a system where no namespace has been provided. This can cause issues for BizTalk Server given that namespace#root is the global unique identifier for messages. If you had installed the BizTalk Adapters for Enterprise Applications, you’d find a Visual Studio.NET project located at:
C:\Program Files\Microsoft BizTalk Adapters for Enterprise Applications\Pipeline Component

This is a custom pipeline component which adds namespaces to messages. For instance, let’s say I have the following XML input coming in …


I can create a receive pipeline with my new SetNSForMsg custom pipeline component.

Notice that I can type in a namespace that will be applied to the message. After deploying this pipeline and running the above message through, I get an output XML message looking like this:

<InputSchema targetNamespace=”http://Blog.BizTalk.NSPipelineTest”&gt;

I stared at that for a few moments and something didn’t look right. I added an XML Disassembler pipeline to my receive pipeline and redeployed. Now when I processed the original message, it got suspended with a notice that an unrecognized format was received. I realized that the component is setting the targetNamespace value vs. setting up the xmlns value the message needed. So, I went into the provided custom pipeline component’s Execute method and changed the line message.DocumentElement.SetAttribute(“targetNamespace“, targetNS); to message.DocumentElement.SetAttribute(“xmlns“, targetNS);. So my current receive pipeline looks like this:

My output messages now look like this:

<InputSchema xmlns=”http://Blog.BizTalk.NSPipelineTest”&gt;

Now THAT’S what I’m looking for. Just to be sure that the disassembling actually succeeded, I stopped the send port, thus suspending the outbound message. Inspecting that message shows me that the Message Type was indeed set:

Sweet. One final cool thing. Now that I have this pipeline, I can use the BizTalk Server 2006 feature to modify pipeline configuration settings for EACH receive location that uses it. You can reuse this pipeline over and over, and just modify the namespace value and document schema.

While on the topic of pipelines, don’t forget to download Tomas’ fancy new PipelineTesting library for running unit tests on your pipeline components.

Technorati Tags:

Author: Richard Seroter

Richard Seroter is Director of Developer Relations and Outbound Product Management at Google Cloud. He’s also an instructor at Pluralsight, a frequent public speaker, the author of multiple books on software design and development, and a former editor plus former 12-time Microsoft MVP for cloud. As Director of Developer Relations and Outbound Product Management, Richard leads an organization of Google Cloud developer advocates, engineers, platform builders, and outbound product managers that help customers find success in their cloud journey. Richard maintains a regularly updated blog on topics of architecture and solution design and can be found on Twitter as @rseroter.

26 thoughts

  1. Richard
    Very Good article and it will be usefull to all the biztalk guys who struggle with name spaces often.Was looking for this kind of article for while when trying to process xml messages with no name spaces
    Saravana Ramkumar

    1. Why does BT require namespaces in the first place. Namespaces just muck up the xml format and take something that is designed to be super easy to read (xml) and make it cumbersome and stupid to read. Besides, namespaces give you almost zero benefit. Why all the hassle!!!??? Who in their right mind uses them?

      1. Why use strongtype versus sloopy typing
        An xml document is ment to be read by a machine/program not by the human eye, You need the strong type in order to identify and the validate the message automatically otherwise it’s garbage in – garbage out

  2. Darn, I wrote my own and now I discovered this. But I needed an validation of the message anyway which I added as a property for the decode component.

  3. …..

    Thank you very much Richard, I came across a similar situation today and found your post. It is very helpfull.


  4. Hi Richard,
    Thanks for this good info, I am also experiencing the same problem I tried what u said but I could not get the result. I have tried with Biztalk 2006 Enterprise server. Am i missing any pre-requisite for testing this.

  5. Any problem with empty element?

    After introducing this component in my pipeline I get carriage return + line feed in elements that are empty.

    This affects mapping to outgoing flat file in a bad way.

    Any one experience this?

  6. Solved – “Any problem with empty element?”

    I added a XmlWriter before writing to stream, then it corrects the problem with CR LF in empty elements.

    Martin Bring


    //message.DocumentElement.SetAttribute(“targetNamespace”, targetNS);
    message.DocumentElement.SetAttribute(“xmlns”, targetNS);

    MemoryStream outStream = new MemoryStream();
    XmlWriter writer = new XmlTextWriter(outStream, Encoding.UTF8);


  7. Thank you very much for this article, very helpful. I was looking kind of long time, from where I can install “BizTalk Adapters for Enterprise Applications”. Finally I found them on the BizTalk DVD in the folder D:\English\BizTalkServer2006R2\LineofBusinessAdaptersDeveloperEdition\setup.exe



  8. When I first glanced at your articel I thought, this is the solution I need but then my eyes fell on the words “If you had installed..”. We have not so I guess our problems have to be solved in some other way. But thanks anyway

  9. Hi,

    If root tag has an attribute, then when adding namespace it removes the attribute.
    I have XML with …. When this XML goes through pipeline i get , the attributes get cut off.
    Have anyone had this issue?
    I would appreciate your help!


  10. Thanks for the article, however, when I changed the code as suggested to be “xmlns”, and deployed into the pipelines folder in VS I get this error: “You have selected an invalid pipeline component assembly. Please check security settings for the assembly if you are loading it from an UNC path.” Any ideas?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.