Wednesday, January 26, 2011

Recoverable interchange processing

When "false" - indicates that entire interchange is disassembled as a unit (if any contained message fails, entire interchange is suspended).

When "true" - indicates that messages within interchange are extracted individually by disassembler with possibility of some propagating through messaging pathway and others being suspended.

Sunday, January 23, 2011

Using External XSLT in the BizTalk Mapper

The BizTalk Mapper supports custom XSLT in two forms; the script functoid (1) and then in the Mapper itself (2) (this is the one that I was interested in).

1) The script functoid operates on parts of a schema. You can use the script functoid to write inline XSLT for any part of the schema in which the output of the functoid creates the target node and all of its appropriate substructure. However, there can not be any other mappings to this target structure or its substructure.

2) This functionality allows you to use a whole existing XSLT style sheet and use it in your BTS project. To do this

a. Add the source and destination schemas to your project

b. Create the map (.btm file) and add the two schemas to it (but do not do any graphical mappings)

c. Click the grid zone and on the properties window there will be a “Custom XSLT Path” property. Click the ellipses and navigate to the file containing the XSLT.

d. Build the project and deploy. The Mapper will use your XSLT file to perform the mappings.

One thing to be aware of is that if your custom XSLT contains embedded code then the compiler gets loaded each time a map is run. We had an old XSLT that had VB Script. We updated the code to use VB.NET and then we loaded it into the Mapper. When we submitted 20 messages we saw 20 instances of the VBC.EXE process load into memory.

Early Termination with Position Flat Files

When working with flat files, BizTalk assumes that each and every line contains data to match the length of the record you specified in your schema. If the data does not match the length with data then it expects that it will find spaces. It does not expect to find an early CR LF.

For example, I have a flat file with 23 characters per line and have specified that in my schema. The last line, however, only has 20 characters.


ROI1LOANLOANP088ISRTRFD

ROI1LOANLOANP088UPDTRFD

RZA1LOANLOANP076ISRT

(this line ends early and is not filled with spaces)

If the data does not extend out to the end then you will receive an error like the following: 'Unexpected data found while looking for: \r\n'


To make BizTalk recognize an early terminator you need to open your schema in a text editor and add allow_early_termination = "true" to the xs:annotation node. This property is not exposed in the BizTalk XSD editor.


This is a snippet of the schema up to the end of the annotation node.


<?xml version="1.0" encoding="utf-16"?>

<xs:schema xmlns="http://NPP.ML" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://NPP.ML" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:annotation>

<xs:appinfo>

<b:schemaInfo count_positions_by_byte="false" standard="Flat File" root_reference="ML_Multiple" allow_early_termination="true"/>

<schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />

</xs:appinfo>

</xs:annotation>


How to get the source file name in a pipeline component

to retrieve the source file name we would use this following line of code:
string srcFileName = context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties").ToString();


In previous entries I have shown how to access Pipeline Context items. There are a number of 'built in' promoted properties that provide important information. There are different items for the receive and send pipelines.

The 14 receive pipeline items are (including the associated namespace):

1. ReceivedFileName (http://schemas.microsoft.com/BizTalk/2003/file-properties)

2. InboundTransportLocation (http://schemas.microsoft.com/BizTalk/2003/system-properties)

3. InterchangeID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

4. ReceivePortID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

5. ReceivePortName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

6. WasSolicitResponse (http://schemas.microsoft.com/BizTalk/2003/system-properties)

7. AuthenticationRequiredOnReceivePort (http://schemas.microsoft.com/BizTalk/2003/system-properties)

8. InboundTransportType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

9. LRPMsgBodyTracking (http://schemas.microsoft.com/BizTalk/2003/system-properties)

10. MessageExchangePattern (http://schemas.microsoft.com/BizTalk/2003/system-properties)

11. PortName (http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

12. ReceivePipelineID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

13. MessageType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

14. SchemaStrongName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

While the 31 send pipeline items are

1. CopyMode (http://schemas.microsoft.com/BizTalk/2003/file-properties)

2. LTPMsgBodyTracking (http://schemas.microsoft.com/BizTalk/2003/system-properties)

3. ReceivedFileName (http://schemas.microsoft.com/BizTalk/2003/file-properties)

4. SPID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

5. ActualRetryCount (http://schemas.microsoft.com/BizTalk/2003/system-properties)

6. FileName (http://schemas.microsoft.com/BizTalk/2003/file-properties)

7. PartyName (http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

8. ReceivePortName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

9. WasSolicitResponse (http://schemas.microsoft.com/BizTalk/2003/system-properties)

10. AllowCacheOnWrite (http://schemas.microsoft.com/BizTalk/2003/file-properties)

11. RetryInterval (http://schemas.microsoft.com/BizTalk/2003/system-properties)

12. OutboundTransportCLSID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

13. SPName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

14. InboundTransportLocation (http://schemas.microsoft.com/BizTalk/2003/system-properties)

15. InterchangeID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

16. ReceivePortID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

17. SPTransportID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

18. TransmitPipelineID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

19. AuthenticationRequiredOnReceivePort (http://schemas.microsoft.com/BizTalk/2003/system-properties)

20. InboundTransportType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

21. LRPMsgBodyTracking (http://schemas.microsoft.com/BizTalk/2003/system-properties)

22. MessageExchangePattern (http://schemas.microsoft.com/BizTalk/2003/system-properties)

23. OutboundTransportLocation (http://schemas.microsoft.com/BizTalk/2003/system-properties)

24. PortName (http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

25. ReceivePipelineID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

26. SourcePartyID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

27. MessageType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

28. OutboundTransportType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

29. PartNames (http://schemas.microsoft.com/BizTalk/2003/messageagent-properties)

30. RetryCount (http://schemas.microsoft.com/BizTalk/2003/system-properties)

31. SchemaStrongName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

To get access to these properties you need to get access to the context object. The following method shell shows how we can do that.

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)

{

IBaseMessageContext context = pInMsg.Context;

Place code here to work with the context object (look at this blog entry to get more details on this method)

.

.

.

}

Now that we have a method to gain access to the context, what if we want to get access to the internal promoted properties? We can iterate through all of the default promoted properties by using the context.ReadAt method (which produces the list of the items above). This method takes an index and returns, through 2 out parameters, the name and namespace of the properties.

We can also use the context.Read method to access the value of each of these promoted properties. The Read method returns an object type containing the value of the promoted property when passing in the name and namespace of the property.

So, to retrieve the source file name we would use this following line of code:

string srcFileName = context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties").ToString();

Business Rules Group

http://www.businessrulesgroup.org/first_paper/br01c0.htm

Wednesday, January 12, 2011

Using the %SourceFileName% Macro to Create a Custom Send File Name

In Construct Message, Select construct Message Property as output / resonse message(MsgResponse)
Put a Message Assignment shape and put the following expression.

MsgResponse(FILE.ReceivedFileName)=MsgRequest(FILE.ReceivedFileName); or Use can customise here.

Modifying BizTalk Message using .NET




In Message Assignment

MsgOutput=Namespace.Class.NodePositionRecord(MsgISOResponse);

.Net Class Code function:
public static XmlDocument NodePositionRecord(XmlDocument InputMSGRequest)

{
XmlDocument InputDoc = PositionMSGRequest;
try
{

XmlDocument PositionMSGResponse = new XmlDocument(InputDoc.NameTable);

//Your XML Operation

MSGResponse = InputDoc ;

return MSGResponse;

}

catch (Exception ex)

{

return InputMSGRequest;

}

}

private void AddNode(XmlNode node, string elementName)

{

XmlElement newElement = node.OwnerDocument.CreateElement(elementName);

node.AppendChild(newElement);

}

private void AddNode(XmlNode node, string elementName, string value)

{

XmlElement newElement = node.OwnerDocument.CreateElement(elementName);

XmlText elementText = node.OwnerDocument.CreateTextNode(value);

node.AppendChild(newElement);

node.LastChild.AppendChild(elementText);

}
private XmlNode GetNode(XmlDocument doc, string xpath)


{

XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(doc.NameTable); xmlnsManager.AddNamespace("ns0", "http://xyz.BizTalk.ESB.Schemas.BREResult");
return doc.SelectSingleNode(xpath, xmlnsManager);



}