【问题标题】:How to Retrieve the Message Body with an Appropriate Encoding in a Custom WCF LOB Adapter?如何在自定义 WCF LOB 适配器中检索具有适当编码的消息正文?
【发布时间】:2011-03-17 22:49:42
【问题描述】:

我正在尝试编写用于 BizTalk 的基本单向自定义 WCF LOB 适配器。但是,目标系统不一定支持 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]'/>

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

    /// <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;
    }

【问题讨论】:

标签: biztalk wcf-lob-adapter


【解决方案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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多