2011-03-17 38 views
1

我正在尝试编写一个基本的单向自定义WCF LOB适配器以用于BizTalk。但是,目标系统不一定支持Xml消息。据我所知,流过一个自定义的WCF适配器消息在XML信封包裹和消息体可以以四种方式之一来编码:如何使用自定义WCF LOB适配器中的适当编码检索邮件正文?

  • 的Xml
  • 字符串
  • BINHEX
  • Base64

此设置受Outbound WCF message body属性的配置支配,该属性接受的属性如下所示ING 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; 
    } 
+0

我想看看这里:http://blogs.msdn.com/b/distributedservices/archive/2010/01/06/manipulate-a-wcf-request-response-using-a-custom -encoder.aspx – 2011-03-21 21:58:02

回答

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 
} 
相关问题