locked
How can I send out a text message from an orchestration RRS feed

  • Question

  • I have an orchestration where I need to take a string and send it out to a send port.

    Right now I am using a mesage type of string but when it comes through the send port it is wrapped in XML (even though i'm using a passthrough pipeline.).

    How can I keep the message exactly how I send it?

    Example: stringMessage = "Hi how are you!";

    mesage from send port

    <?xml version="1.0"?>
    <string>Hi how are you!</string>

    needs to be

    Hi how are you!

     

     

    Monday, October 18, 2010 6:47 PM

Answers

  • Hi,

    By default BizTalk will serialize any document type in an XML fashion. Message parts that are defined using .NET types are serialized and deserialized using the .Net XML serializing process. A System.String is a standard .Net type, and "100" will become "<?xmlversion="1.0"?><string>100</string>". With carrying out the following steps you can send it as string:

    • Create a simple schema that will have one node.  ex. <ns0: Document
      xmlns:ns0='your namespace'><DocumentContent></DocumentContent></Document>.
      Call this SchemaA.
    • Inside your orchestration, declare a message of type SchemaA.  Call it
      MessageA.
    • Inside your orchestration, declare a variable of type string.  Call it
      VariableA.  Also declare a variable of type XmlDocument, call it XmlDcoumentA.
    • In an expression shape, VariableA = @"<ns0:Document xmlns:ns0='your
      namespace'><DocumentContent>" + "The string message you want to send" +
    • In the same expression shape, XmlDocumentA = new System.Xml.XmlDocument();
      XmlDocumentA.LoadXml(VariableA);
    • In a Message Assignment shape, MessageA = XmlDocumentA;
    • In a Send Shape, set the Message to be MessageA.
    • Create a Send Pipeline and assign SchemaA to a Flat file assembler
      pipeline component under the Assemble section.
    • Attach this send pipeline to your send port.

    HTH

    Regards,

    Steef-Jan Wiggers - MVP & MCTS BizTalk Server
    blog: http://soa-thoughts.blogspot.com/
    If this answers your question please mark it accordingly


    BizTalk
    Monday, October 18, 2010 7:25 PM
    Moderator

All replies

  • Hi,

    By default BizTalk will serialize any document type in an XML fashion. Message parts that are defined using .NET types are serialized and deserialized using the .Net XML serializing process. A System.String is a standard .Net type, and "100" will become "<?xmlversion="1.0"?><string>100</string>". With carrying out the following steps you can send it as string:

    • Create a simple schema that will have one node.  ex. <ns0: Document
      xmlns:ns0='your namespace'><DocumentContent></DocumentContent></Document>.
      Call this SchemaA.
    • Inside your orchestration, declare a message of type SchemaA.  Call it
      MessageA.
    • Inside your orchestration, declare a variable of type string.  Call it
      VariableA.  Also declare a variable of type XmlDocument, call it XmlDcoumentA.
    • In an expression shape, VariableA = @"<ns0:Document xmlns:ns0='your
      namespace'><DocumentContent>" + "The string message you want to send" +
    • In the same expression shape, XmlDocumentA = new System.Xml.XmlDocument();
      XmlDocumentA.LoadXml(VariableA);
    • In a Message Assignment shape, MessageA = XmlDocumentA;
    • In a Send Shape, set the Message to be MessageA.
    • Create a Send Pipeline and assign SchemaA to a Flat file assembler
      pipeline component under the Assemble section.
    • Attach this send pipeline to your send port.

    HTH

    Regards,

    Steef-Jan Wiggers - MVP & MCTS BizTalk Server
    blog: http://soa-thoughts.blogspot.com/
    If this answers your question please mark it accordingly


    BizTalk
    Monday, October 18, 2010 7:25 PM
    Moderator
  • You have to make a custom pipeline and drag the assembler pipeline component in the assemble stage. Also make a flat file schema and configure the assembler component document schema property by assigning it to the Flat file schema you created. Deploy the solution and at the send port configure your custom send pipeline.

    The Flat file schema could be created by the flat file schema wizard in which you can have a sample text file with a single text message.


    Abdul Rafay - MVP & MCTS BizTalk Server
    blog: http://abdulrafaysbiztalk.wordpress.com/
    Please mark this as answer if it helps.
    Monday, October 18, 2010 8:47 PM
  • Good answers Steef and Rafay :) , Why dont you guys let me answer Lol. just kididng ........
    BizTalk Developer UBL Transformation
    Tuesday, October 19, 2010 5:52 AM
  • since you probably only send relatively small strings, it's also very easy to create a custom pipeline component that will deserialize the <string>yourstring</string>.

    This will save you the hassle of assigning stuff in orchestrations and / or schema's. Here is some sample code you could use.

           public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
            {
                if (this.Active == true)
                {
                    try
                    {
                        // Load up the message we received from the stream
                        System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
                        xDoc.Load(inmsg.BodyPart.GetOriginalDataStream());

                        // Now perform the xpath query to get the first
                        System.Xml.XmlNode node = xDoc.SelectSingleNode("/string");
                        string payload = node.FirstChild.Value;

                        // Now write the payload back to the stream
                        // And convert the string back to a stream.
                        MemoryStream outputStream = new MemoryStream();
                        StreamWriter outputWriter = new StreamWriter(outputStream);
                        outputWriter.Write(payload);
                        outputWriter.Flush();
                        // Make sure we set position to 0
                        outputStream.Seek(0, SeekOrigin.Begin);
                        //Change the data part of the message
                        inmsg.BodyPart.Data = outputStream;
                        //The memory stream object must persist after you've left the function
                        pc.ResourceTracker.AddResource(outputStream);
                        // And clean up.
                        xDoc = null;
                        outputWriter = null;
                        node = null;

                    }
                    catch (Exception ex)
                    {
                       
                        throw ex;
                    }
                }
                return inmsg;
            }

     

     

     


    Well0549, Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread
    Tuesday, October 19, 2010 8:35 AM