1

我正在尝试编写一个基本的单向自定义 WCF LOB 适配器以在 BizTalk 中使用。但是,目标系统不一定支持 Xml 消息。我了解流经自定义 WCF 适配器的消息被包装在 XML 信封中,并且消息正文可以通过以下四种方式之一进行编码:

  • xml
  • 细绳
  • BinHex
  • Base64

此设置由属性的配置控制,该Outbound WCF message body属性接受类似于以下 XML 片段的属性:

<bts-msg-body xmlns='http://www.microsoft.com/schemas/bts2007' encoding='[xml|base64|hex|string]'/>

Execute在我的类中方法的实现中CustomAdapterOutboundHandler,如何检索已在发送端口配置上指定的编码?

    /// <summary>
    /// Executes the request message on the target system and returns a response message.
    /// If there isn’t a response, this method should return null
    /// </summary>
    public Message Execute(Message message, TimeSpan timeout)
    {
        // ISSUE: how to retrieve the message body as binary byte[] / stream / whatever ?
        // <bts-msg-body xmlns='http://www.microsoft.com/schemas/bts2007' encoding='[xml|base64|hex|string]'/>

        System.Xml.XmlDictionaryReader reader = message.GetReaderAtBodyContents();

        return null;
    }
4

1 回答 1

1

终于发现了。。

像下面这样的代码就可以了。

object strvalue;
bool result = Message.Properties.TryGetValue("http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties#OutboundXmlTemplate", out strvalue);
if (result)
{
  XmlDocument xmldoc = new XmlDocument();
  xmldoc.LoadXml(strvalue.ToString());
  string btsencoding = xmldoc.SelectSingleNode("//*[local-name()='bts-msg-body']").Attributes["encoding"].Value;

// do something useful
}
于 2011-05-05T19:22:03.040 回答