1. Create new BizTalk Server project in Visual Studio and add the new RecipientListService orchestration. |
|
2. Add references to the following ESB Toolkit assemblies: |
- Microsoft.Practices.ESB.Adapter
- Microsoft.Practices.ESB.ExceptionHandling
- Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults
- Microsoft.Practices.ESB.Itinerary
- Microsoft.Practices.ESB.Itinerary.Schemas
- Microsoft.Practices.ESB.Resolver
- Microsoft.Practices.ESB.Transform
|
|
3. Define a logical direct-bound Receive Port and an activated Receive Shape in the Orchestration. |
|
4. Define a subscription filter to the Receive Shape to activate the orchestration from the message itinerary context so that the orchestration executes the RecipientListService step. |
![FilterExpression FilterExpression]() |
|
5. Add an Expression Shape to the orchestration with the following code to retrieve the current itinerary step. |
// Retrieve the current itinerary step itinerary = new Microsoft.Practices.ESB.Itinerary.SerializableItineraryWrapper(); itineraryStep = new Microsoft.Practices.ESB.Itinerary. SerializableItineraryStepWrapper(); itinerary.Itinerary = Microsoft.Practices.ESB.Itinerary. ItineraryOMFactory.Create(InboundMessage); itineraryStep.ItineraryStep = itinerary.Itinerary.GetItineraryStep(InboundMessage); |
|
6. Add an Expression Shape to the orchestration with the following code to retrieve the Resolvers associated with the itinerary. |
// Init resolverDictionary = null; // Retrieve the Resolvers associated with the itinerary resolvers = itineraryStep.ItineraryStep.ResolverCollection; |
|
7. Add a Decide shape with the rule “resolvers.Count > 0” |
|
8. Add a Loop Shape to the orchestration with the expression “resolvers.MoveNext()” to loop through the Resolvers. |
![Loop through Resolvers Loop through Resolvers]() |
|
9. Add an Expression Shape to the orchestration with the following code to retrieve the Resolver properties. |
// Retrieve current resolver resolver = resolvers.Current; // Pass the resolver configuration to the Resolver mgr for resolution resolverDictionary = Microsoft.Practices.ESB.Resolver. ResolverMgr.Resolve(InboundMessage, resolver); // Get properties mapName = resolverDictionary.Item("Resolver.TransformType"); transportLocation = resolverDictionary.Item("Resolver.TransportLocation"); transportType = resolverDictionary.Item("Resolver.TransportType"); |
|
10. Add a Decide shape with the rule “mapName != null && mapName != " |
![TransformMessage TransformMessage]() |
|
11. Add an Expression Shape to the orchestration with the following code to transform the message. |
// Transform message transformedMsgXml = Microsoft.Practices.ESB.Transform.MapHelper. TransformMessage(InboundMessage.Body.OuterXml, mapName); // Create XmlDocument xmlDoc.LoadXml(transformedMsgXml); |
12. Add a Message Assignment Shape to the orchestration with the following code to create the ESBRequest message and set the dynamic port properties. |
// Create ESB Message ESBMessage.Body = xmlDoc; // Call the Adapter Manager to set all necessary properties Microsoft.Practices.ESB.Adapter.AdapterMgr.SetEndpoint(resolverDictionary,ESBMessage); // Set delivery port address DynamicPort(Microsoft.XLANGs.BaseTypes.Address) = transportLocation; DynamicPort(Microsoft.XLANGs.BaseTypes.TransportType) = transportType; |
|
13. Create a Port with a Dynamic binding and add a Send Shape to the orchestration to send the ESBRequest message to the Recipient. |
![SendMessageToRecipient SendMessageToRecipient]() |
|
14. Add a Message Assignment Shape to the orchestration with the following code to create the Outbound message and set the dynamic port properties. |
// Create message OutboundMessage.Body = xmlDoc; OutboundMessage(*) = InboundMessage(*); // Call the Itinerary helper to advance to the next step hasMoreSteps = itinerary.Itinerary.HasNextService(); itinerary.Itinerary.Advance(OutboundMessage, itineraryStep.ItineraryStep); itinerary.Itinerary.Write(OutboundMessage); |
|
15. Add a Decide shape with the rule “hasMoreSteps” |
|
16. Create a Correlation Type and a Correlation Set for the itinerary. |
![CorrelationProperties CorrelationProperties]() |
|
17. Create a Port with a Direct binding and add a Send Shape (with the Correlation Set) to the orchestration to send the Outbound message back to the MessageBox database. |
![SentMessageToMessageBox SentMessageToMessageBox]() |
|
18. Add an Exception handler to the Main scope to catch all the exceptions. (You can also have exception handlers on other scopes) |
|
19. Add a Message Assignment Shape to the Exception handler with the following code to create a Fault Message. You can add multiple messages to the FaultMessage. |
// Trace System.Diagnostics.Trace.WriteLine("[RecipientListService] Exception:" + ex.Message); // Create FaultMessage FaultMessage = Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt. CreateFaultMessage(); // Set Fault Message Properties FaultMessage.Body.FaultCode = "2111"; FaultMessage.Body.FaultDescription = "Exception"; FaultMessage.Body.FailureCategory = "Routing Failure"; FaultMessage.Body.FaultSeverity = Microsoft.Practices.ESB.ExceptionHandling. FaultSeverity.Critical; // Add message Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.AddMessage (FaultMessage, InboundMessage); |
|
20. Create a Port with a Direct binding and add a Send Shape to the orchestration to send the FaultMessage message back to the MessageBox database. |
![SendFaultMessage SendFaultMessage]() |
|
21. Right click on the BizTalk project and click in the Menu on the Properties item. Click on the signing tab to create Strong Name Key. |
|
22. Click on the Deployment tab to configure the Deployment properties and set the Application Name. |
|
23. Right click on the BizTalk project and select Build to create the assembly. |
|
24. Right click on BizTalk project and click on Deploy to deploy the Orchestration. |
|
25. In the BizTalk Administration Console go to the created application and configure the Bindings of the orchestration and start the application. |
|