印刷用ページ       送信     
クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
BizTalk Server
BizTalk Server 2006
開発
Creating Orchestrations
Using Messages in Orchestrations
Constructing Messages
 Constructing Messages in User Code

  低帯域幅での表示をオンにする
 
Constructing Messages in User Code 

You can represent BizTalk messages at design time as either XSD schemas or .NET classes.

A template XML instance of the XSD message type is defined at design time and then stored on disk. At run time, a .NET component picks up the XML from disk and returns it as an XmlDocument. The orchestration code can assign this XmlDocument result to the message instance declared in the orchestration.

The Message Assignment shape has a single line of code:

MsgOut = CreateMsgHelper.Helper.GetXmlDocumentTemplate();

The Helper Component that creates the XmlDocument has a single static method:

private static XmlDocument _template = null;
private static object _sync = new object();
private static String LOCATION = @"C:\MyTemplateLocation\MyMsgTemplate.xml";

public static XmlDocument GetXmlDocumentTemplate()
{
   XmlDocument doc = _template;
   if (doc == null)
   {
      // Load the doc template from disk.
      doc = new XmlDocument();
      XmlTextReader reader = new XmlTextReader(LOCATION);
      doc.Load(reader);

      // Synchronize assignment to _template.
      lock (_sync)
      {
         XmlDocument doc2 = _template;
         if (doc2 == null)
         {
            _template = doc;
         }
         else
         {
            // Another thread beat us to it.
            doc = doc2;
         }
      }
   }

   // Need to explicitly create a clone so that we are not
   // referencing the same object statically held by this class.
   doc = (XmlDocument) doc.CloneNode(true);
   return doc;
}

This approach first involves creating a .NET class that defines your message type. A simple example of such a class is shown here.

using System;
using Microsoft.XLANGs.BaseTypes;

namespace NetClass
{
   [Serializable]
   public class MsgClass
   {
      public MsgClass()
      {
         StrField = "OK";
         IntField = 1;
      }

      [DistinguishedFieldAttribute()]
      public String StrField;

      [DistinguishedFieldAttribute()]
      public int IntField;
   }
}

Once the message type is defined, it is very easy to write code in the orchestration that will create a new message of this type. Within a Construct Message shape, you write simple expressions to create a new message of the MsgClass type shown above, and then assign values to the fields which are attributed as Distinguished Fields (if you wish to override the default values). Note that MyMsg is an orchestration message variable whose type is NetClass.MsgClass.

MyMsg = new NetClass.MsgClass();
MyMsg.StrField = "Changed Value";
MyMsg.IntField = 15;

There may be times when you want to create a new message without transforming a source message. This can be done by using by using a variable of type System.Xml.XmlDocument and either loading or otherwise constructing appropriate content.

In this example, XML is loaded from a string using the LoadXml method of XmlDocument:

XmlVariable.LoadXml("<ns0:Root PONumber=\"047745351122111\" xmlns:ns0=\"http://BTSHTTPSend.SimpleSchema\"><MyChildRecord SubAttr1=\"Simple Attribute \" /></ns0:Root>");
XLANGMessage XmlMsg = XmlVariable;

This example loads XML from a file using the Load method of XmlDocument:

XmlVariable.Load("C:\MyData.xml");
XLANGMessage XmlMsg = XmlVariable;
メモ
If you want to construct larger messages, use one of the streaming methods demonstrated in the previous sections or consider using the Transform shape.

その他の技術情報

Constructing Messages

© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker