BizTalk Integration with Windows Azure AppFabric Service Bus : Publishing BizTalk Server messages to the Service Bus
BizTalk Server 2010 is a straightforward consumer of Azure Service Bus messages. As more organizations introduce cloud solutions into their enterprise architecture, we will see an increasing need to seamless orchestrate these endpoints with on-premises data and systems. A cloud service can be invoked by BizTalk Server quite easily and makes BizTalk a valuable asset when integrating between clouds or between on-premises and the cloud.
Scenario description
In this scenario, we continue our work with the WatsonBSafe and Riley Semiconductor organizations. If you recall from the last exercise, WatsonBSafe has a need to query the Riley Semiconductor's training system so that they can uncover which courses are required by an employee before access is granted to a building or room. The training service is exposed through the Service Bus and needs to be invoked by BizTalk Server 2010.
Solution design
For this solution, we will use BizTalk Server's WCF-CustomIsolated adapter alongside a Service Bus binding to call the training service. Because this service only looks up data and does not require granular security, we will not apply any security above and beyond the standard Service Bus authentication process.
Building the Access Control Service components
The first thing we need is the Service Bus STS configuration for our vendor's training service. In our previous demonstration, WatsonBSafe was hosting a service that Riley Semiconductor was sending to. Here, the roles are reversed.
Open the AcmBrowser application and log in to the Service Bus STS using your namespace (plus "-sb" suffix) and default issuer key.
Add a new Scope named TrainingServices and set the scope's Applies To URL to http://<your namespace>.servicebus.windows.net/TrainingServices
Create a new rule named Listen where the input claim Issuer is Riley Semiconductor, the Type is Issuer, and the Value is Riley Semiconductor. The output claim type is net.windows.servicebus.action with a value of Listen.
Define a second rule named Send that uses the WatsonBSafe Issuer, has a Type of Issuer, and a Value of WatsonBSafe. The output claim type is net.windows.servicebus.action with a value of Send. This rule issues a token allowing the service consumer to call the service if they know the credentials for the WatsonBSafe Issuer.
Save the Service Bus STS configuration back to the cloud.
Return to Visual Studio 2010 and open the Chapter6.TrainingService project that exists in the solution.
Open the web.config file for the service and make the following changes:&;
Complete the endpoint address for each endpoint under system.ServiceModel/services/service by filling in your own Service Bus namespace.
Set valid issuer secrets for the two behaviors at system.serviceModel/behaviors/endpointBehaviors.
Build and deploy the TrainingService and view the service in the browser to ensure a successful binding to the cloud.
Our TrainingService is now complete and ready for BizTalk Server to invoke it.
Building the BizTalk solution components
We are going to build a few BizTalk components for calling the TrainingService and combining its result with the access request message in order to emit a single message containing both the employee requesting access and the training required for access to be granted.
Open the existing BizTalk Server project in the Visual Studio 2010 solution.
Create a new schema named AccessRequirements_XML.xsd. This schema holds a combination of access request details and required training courses related to the access request. All of the elements have a data type of "string."
Ensure that the schema above has the Course node set to be unbounded to support an unlimited number of assigned courses.
Now we are ready to reference our cloud-hosted TrainingService and produce the BizTalk artifacts needed to call the service. Right-click the BizTalk project in Visual Studio 2010 and choose to Add Generated Items. Select the option to Consume WCF Service.
When prompted, put in the MEX address for the service (for example, https://<your namespace>.servicebus.windows.net/TrainingServices/TrainingService.svc_mex) and click the Get button. You will likely see an error but that has no negative impact. A MEX query is done via SOAP, and this wizard is only doing a simple HTTP GET request. Therefore, the error is expected.
Complete the BizTalk WCF Service Consuming Wizard and notice that the wizard adds schemas, an orchestration, and a binding file to the BizTalk project.
Create a new orchestration named VerifyRileyAccessRequirements.odx in the BizTalk project. This orchestration listens for building access requests from the Riley Semiconductor company and calls back through the cloud to the Riley Semiconductor's training system to look up required training for the requested building. We would conceptually have one orchestration for each partner, or, could alternately build a more loosely coupled orchestration that relies more on send port maps for destination specific formats. In this scenario, we'll build vendor-specific orchestrations.
Define four orchestration-level messages:
AccessRequestInput of type Chapter6.BuildingAccessManagement.BizTalk.AccessRequestEvent_XML
EmployeeTrainingOutput of type Chapter6.BuildingAccessManagement.BizTalk.AccessRequirements_XML
TrainingServiceRequest of multi-part type Chapter6.BuildingAccessManagement.BizTalk.ITrainingService_GetTrainingForBuildingAccess_InputMessage
TrainingServiceResponse of multi-part type Chapter6.BuildingAccessManagement.BizTalk.ITrainingService_GetTrainingForBuildingAccess_OutputMessage
Add a filter on the initial receive shape of the orchestration. This filter will ensure that only messages from Riley Semiconductor come into this orchestration.
After the topmost receive shape, add a Construct/Transform block that is responsible for building the service's request message.
Double-click the Transform shape and choose the option to create a new map named BizTalk.AccessRequest_To_TrainingServiceRequest. This map should start with the AccessRequestInput message and output the TrainingServiceRequest message.
Within the map, connect the LocationId, BuildingNumber, and RoomNumber to the corresponding nodes in the target schema. Save the map and return to the orchestration.
Add a Send shape and Receive shape below the previous Construct shape. These new shapes are responsible for calling the TrainingService and receiving the response message. Set the Send shape to use the TrainingServiceRequest message and the Receive shape will use the TrainingServiceResponse message.
Create a new, configured port on the Port Surface portion of the orchestration. For the Port Type value, choose to use an existing port type and point to the one created by the service reference. Our orchestration should look like the following image:
Next, we need to mash up our original message with the result of the service call. Add a new Construct/Transform block at the bottom of the orchestration.
Double-click the Transform shape and create a new map named AccessRequestTrainingResponse_To_EmployeeTrainingOutput.
The input to the map is BOTH the AccessRequestInput and TrainingServiceResponse message and outputs the EmployeeTrainingOutput message. You may remember that you can create multi-part maps in BizTalk Server, but only from within an orchestration. You cannot create a multi-part map from within the Mapper itself.
Connect the relevant source nodes to the destination nodes.
Add a final send shape that uses the EmployeeTrainingOutput message.
Define an orchestration receive port for the initial Receive shape and an orchestration send port for the last Send shape. The topmost orchestration receive port should be Direct Bound, which means that it listens to the MessageBox for data instead of being bound to a messaging port.
Build and deploy the updated BizTalk solution.
We now have all the compiled components necessary to consume the cloud service from BizTalk Server. Next, we need to configure the BizTalk messaging components to communicate with Windows Azure AppFabric.&;
Configuring BizTalk Solution to use Service Bus bindings
Our final exercise is to configure the BizTalk messaging components.
Switch to the BizTalk Server Administration Console and find the Chapter6 application.
We need two messaging ports. First, we need the two-way send port that calls the TrainingService through the Service Bus. Instead of manually building this port, we can use the binding file that the BizTalk WCF Service Consuming Wizard produced. Right click the Chapter6 application and choose Import, then Bindings, and navigate to the TrainingService_Custom.BindingInfo.xml file residing in the folder with our BizTalk project code.
After the binding is imported, we can see a new Send Port in the application. Opening that port shows us the cloud address, cloud binding, and valid WCF action.
Switch to the Behaviors tab and add a new Endpoint Behavior. Find the TransportClientEndpointBehavior and set the valid "send" credentials for the Service Bus. In our case, this is the WatsonBSafe issuer and secret key from the Service Bus STS.
Our final messaging port is a one-way send port that transmits the final message from the orchestration. Create a file send port that emits a message to the file system.
With the messaging ports complete, we can complete our orchestration binding. Go to our orchestration in the Chapter6 application and match the Outbound Logical Ports to the appropriate Send Ports / Send Port Groups.
Start the send ports and orchestration.