Marko Apfel - Afghanistan/Belgium/Germany

Management, Architecture, Programming, QA, Coach, GIS, EAI

  Home  |   Contact  |   Syndication    |   Login
  187 Posts | 2 Stories | 201 Comments | 4 Trackbacks

News



Twitter | LinkedIn | Xing

Archives

Post Categories

Image Galleries

BizTalk

C#

Enterprise Library

SAP

SQL Server

Technologie

 

Mapping <Any>-Elements in a BizTalk-Map is not possible. You can not draw a direct connect from or to <Any>-Elements.

Some sources in the web describe the possibility to use a scripting-functoid with a special XSLT to do that, other sources recommand to write a special .NET-component to insert the wished tree under the <Any>-Element.

My way use the XmlDocument.ImportNode()-method to do that. The need for me was to create a message wich contains the request to and the response from my own adapter to trace errors wich occured during the execution of this adapter (adapter writes some business-entities to our intranet-database).

So the messages IntranetDbRequest (msgEai) and IntranetDbResponse (msgIntranetDbResp) should be aggregated to IntranetDbEx.

IntranetDbResponse:

IntranetDbEx:

Because our messages makes extensivly usage of XML-Namespaces we need namespace-managers. Now the XmlNamespaceManager-class dont implements the ISerializable-interface. So we musst drill this class. Since we need this extended XmlNamespaceManager only in one shape, we can do that very simply. Scott Colestock describes that very good in his post Atomic scope abuse. His sample with XmlNode we use also.

The XmlNamespaceManagerEx-class :

   1:  [Serializable]
   2:  public class XmlNamespaceManagerEx : ISerializable
   3:  {
   4:     private XmlNamespaceManager _xmlNamespaceManager;
   5:     public XmlNamespaceManager XmlNamespaceManager
   6:     {
   7:        get { return _xmlNamespaceManager; }
   8:        set { _xmlNamespaceManager = value; }
   9:     }
  10:      public XmlNamespaceManagerEx() { }
  11:   
  12:      private XmlNamespaceManagerEx(SerializationInfo info, StreamingContext context) { }
  13:     public void GetObjectData(SerializationInfo info, StreamingContext context){}
  14:  }

Scott Colestocks XmlNodeEx-class:

   1:  [Serializable]
   2:  public class XmlNodeEx : ISerializable
   3:  {
   4:     private XmlNode _xmlNode;
   5:     public XmlNode XmlNode
   6:     {
   7:        get{return _xmlNode;}
   8:        set{_xmlNode = value;}
   9:     }
  10:   
  11:     public XmlNodeEx(){}
  12:   
  13:     public string InnerText
  14:     {
  15:        get{return _xmlNode.InnerText;}
  16:        set{_xmlNode.InnerText = value;}
  17:     }
  18:   
  19:     public static string GetInnerText(XmlNode node)
  20:     {
  21:        return node.InnerText;
  22:     }
  23:   
  24:     private XmlNodeEx(SerializationInfo info, StreamingContext context){}
  25:   
  26:     public void GetObjectData(SerializationInfo info, StreamingContext context){}
  27:  }

Now its time for the orchestration.We need a "Construct Message"-shape with a "Transform"- and a "Message Assignment"-shape inside.

The referenced map in the "Transform"-shape only maps the request. This part ist straight forward. The left side ist connected to the right with using the "SHIFT"-key during drawing the connection at the top level.

In the "Message Assignment"-shape is the <Any>-mapping-intelligence:

   1:  vXmlDocumentIntranetDbResponse = msgIntranetDbResp;
   2:  vNsMgrIntranetDbResponse.XmlNamespaceManager = 
   3:      new System.Xml.XmlNamespaceManager(vXmlDocumentIntranetDbResponse.NameTable);
   4:  vNsMgrIntranetDbResponse.XmlNamespaceManager.AddNamespace("ns0",
   5:      "http://EsriDe/Eai/BizTalk/Schema/IntranetDbResponse/V3.0");
   6:  vXmlNodeIntranetDbResponse.XmlNode = vXmlDocumentIntranetDbResponse.SelectSingleNode(
   7:      "//ns0:Return/Error", vNsMgrIntranetDbResponse.XmlNamespaceManager);
   8:   
   9:  vXmlDocumentIntranetDbEx = msgIntranetDbEx;
  10:  vNsMgrIntranetDbEx.XmlNamespaceManager = 
  11:      new System.Xml.XmlNamespaceManager(vXmlDocumentIntranetDbEx.NameTable);
  12:  vNsMgrIntranetDbEx.XmlNamespaceManager.AddNamespace("ns0",
  13:      "http://EsriDe/Eai/BizTalk/Schema/IntranetDbEx/V3.0");
  14:  vXmlNodeIntranetDbEx.XmlNode = vXmlDocumentIntranetDbEx.SelectSingleNode(
  15:      "//ns0:IntranetDbEx/Response/Return/Error", vNsMgrIntranetDbEx.XmlNamespaceManager);
  16:   
  17:  vXmlNodeIntranetDbEx.XmlNode.AppendChild(
  18:      vXmlDocumentIntranetDbEx.ImportNode(vXmlNodeIntranetDbResponse.XmlNode, true));

The last line imports the whole XmlNode from the response-document in the aggregated document.

posted on Wednesday, February 14, 2007 4:21 PM