24

Jan

2008

How to control XML encoding in BizTalk Server 2004

A classic mistake in BizTalk is to think that you can control more than you really can through schemas. For example, although you can specify default values within a schema (say for a attribute value), this has no effect on message construction and output. Schemas are for validation, mapping, data-typing.etc. They don’t control message construction or value output.

A related issue that came up recently was how to control XML encoding. BizTalk defaults to UTF-8 for XML encoding, and a client of ours had been trying to change this by modifying their XSDs. This does not work.  You control XML encoding by using the XML assembler within the send pipeline . By default, the XML Assembler outputs XML in UTF-8. If you are using a bespoke pipeline, you can change this behaviour by simply setting the TargetCharset property of the XML Assembler component within Visual Studio.

If your outbound message passes through an orchestration, there is another approach you can use. In your orchestration, simply introduce an expression shape before the message is sent, or use an appropriate existing message assignment shape and add the following XLANG/s code.

someMessage(XMLNorm.TargetCharset) = “UTF-16”;

where someMessage is an orchestration message object that contains the message you are sending. This code will set a contextual property on the message that will tell the XML assembler to output UTF-16 rather than UTF-8. You can use this approach with the ‘built-in’ XML send pipeline which already contains the XML assembler component.

Comments are closed.