(See update below)
If you have attempted to send email from BizTalk, you’ve gotten pretty comfortable with this documentation topic.
It discusses how to use a sample class (Microsoft.XLANGs.CustomFormattersSDK.RawString) and associated custom formatter to deal with messages that contain raw string content. As the docs say, “Sending a message of type System.String will not work, because the string gets formatted as an XML document in the message, which is not your desired solution.” (In other words, whether you send or receive, using System.String as a message type means you are dealing with a wrapping tag.)
However, though the docs cover sending RawStrings, it is less clear how you can use the RawString class when you want to receive messages as such. Just typing the port operation as RawString will yield a UnexpectedMessageTypeException, because none of the default receive pipelines will set the MessageType context property on inbound messages to be RawString – and this type matching is what orchestrations expect.
We need a custom receive pipeline that will set the MessageType context property equal to the fully qualified type name for RawString. Jon’s discussion of receiving binary messages provides some background here, and Jon’s ContextAdder pipeline component can make the MessageType context property assignment very easy.
Here are the steps required to receive RawStrings:
Now you will have full access to the raw string content, and can do whatever you need to do…You might want to declare an orchestration variable of type RawString, and assign it to the RawString message so you can access properties/methods like ToString(), which returns the underlying string content.
Update:
Greg Van de Wiele has pointed out the other way to go about this (and Jon has talked about this approach in his recent posts as well.) It can be less work in that no custom pipeline is required (a one time task) - though perhaps a little harder to explain to the “next guy“...you can decide!
It goes like this:
Note that not wrapping the RawString in a multipart message doesn't work - you will get a compiler error indicating that assignments can't be made between XmlDocument and RawString types. Also note that introducing an intermediate message has a performance cost.
Scott Colestock lives, writes, and works as an independent consultant in the Twin Cities (Minneapolis, Minnesota) area.