Share via


How to support windows and UNIX flat file at BizTalk end?

Introduction

Recently I came to scenarios where I have to expose my receive location as web service. Were publisher uses to publish flat file message in form of string to web service.

We did that but during processing of message some messages fail due to below error.

Unexpected data found while looking for: '\r\n'

In able to kneel down the issue we verified the incoming message and able to find out the message published from various publisher are using different system. I mean to say some are using windows and some are using UNIX system.

For Unix the new line are represented by \n

And for windows the new line are represented by \r\n

By default defining delimiter at schema level to separate record can either support \n or \r\n.

So in order to support both functionality either we have to move to \n or \r\n. either we can request our few publisher to do changes at their end or we need to accommodate changes at our end.

In order to support functionality at our end we created custom pipeline component, where it just changes the \n with \r\n in one case and on other case it use to ignore. That way I have converted the incoming string to one format. My system was able to process the message. Below is the code snippest.In order to accommodate both changes we created pipeline component and added at decode stage .

I did below list of changes so that it can support file from both systems.

XmlNode node = originalMessageDoc.SelectSingleNode("//Message");

 int i = node.InnerText.IndexOf("\r");

 if (i < 1)

 {

     strInputString.Append(node.InnerText.Replace("\n", "\r\n").Trim());

 }

 else

 {

     strInputString.Append(node.InnerText.Replace("\r", "").Trim());

     strInputString.Replace("\n", "\r\n");

 }

 memStream.Write(Encoding.ASCII.GetBytes(strInputString.ToString().Trim() + "\r\n"), 0, Encoding.ASCII.GetByteCount(strInputString.ToString().Trim() + "\r\n"));

 memStream.Position = 0;

 msgPart.Data = memStream;

 //StreamReader reader = new StreamReader(memStream);

 //string text = reader.ReadToEnd();

 pInMsg.BodyPart.Data = msgPart.Data;

 pContext.ResourceTracker.AddResource(memStream);

See Also

Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.