MABS EAI Bridge LoB Lookup (Part 1 of 2)
Microsoft Azure BizTalk Services (MABS) has a lot to offer for companies looking for a PaaS Middleware solution. EAI bridges provide B2B communication as well as LoB access functionality for EDI, XML, and flat file interchanges. The new mapping system offers some exciting and powerful new functionality as well, vastly simplifying certain tasks that previously required several functiods, and opening up new possibilities and enhanced performance with lists.
However, it is a new technology, and certain tasks that have been very straightforward in BizTalk Server 2013 require a different way of thinking for MABS. For example, it is a fairly trivial task to create an orchestration that accesses a LoB adapter (using, for example, WCF slqBinding) to do data validation or enhancement, and publishing this orchestration as a web service for client consumption. If your SQL database is SQL Azure, there is some built in functionality to do a “Lookup” in the Azure database, but this may not be an option for an infrastructure that is makes use of features not currently available in SQL Azure, such as the ability to encrypt at rest. It may also just be possible that an existing LoB SQL database cannot easily be moved for various other reasons. In this series of posts, I will outline the process for implementing this functionality using the powerful custom code functionality available in MABS.
The tasks include the following (this post will cover steps 1-6):
- Creating the BizTalk services
- Setting up BizTalk Adapter Services in a local (or IaaS) environment to run a stored procedure in SQL Server
- Creating a sample table and stored procedure
- Creating a ServiceBus namespace with ACS
- Create the Relay to the LOB system
- Creating an EAI bridge to access the LoB system
- Testing and debugging the bridge with a Visual Studio add on
- Writing a custom component to call the LoB adapter in a EAI Bridge Stage and parse the response
- Having the component send an email notification using an Office 365 server
Step 1: Create BizTalk Service This is fairly straightforward. Log into your Azure portal, click BizTalk Service, click New, and then Custom Create. Choose a name, edition, and region, and your service will begin provisioning:
You’ll need the ACS Information for your newly created service for several of the following steps. You can get this information by selecting the service you created and clicking “Connection Information” at the bottom. That will display the following information. You’ll need similar information for the ServiceBus relay (created in step 4) as well; I found it convenient to copy this information into an Excel sheet for quick reference during development (however, be sure this is stored in a secure manner and is consistent with your IT security policies – this is sensitive information that should not be disclosed to non-administrators of the service):
Step 2: Setting up BizTalk Adapter Services For this, you’ll need to get the BizTalk Services SDK: http://www.microsoft.com/en-us/download/details.aspx?id=39087. The instructions for this can be found at: http://msdn.microsoft.com/en-us/library/azure/hh689760.aspx#BKMK_Installation. Take note of the requirement regarding machine.config if you have previously installed Azure BizTalk SDK components, and install the optional runtime (this had me going in circles for a while!). Also take note of the requirements for downloading and installing the certificate from the Azure:
To add it to your security store (see http://msdn.microsoft.com/en-us/library/azure/hh949825.aspx):
- On your test/development machine, double-click the .cer file. Select Install Certificate.
- Select Place all certificates in the following store, select Browse, and select Trusted Root Certification Authorities.
- Complete the installation. You’ll get a Security Warning; which is normal. Click Yes.
When prompted for the service identity, be sure to use an account that has internet access and permissions SQL (or whatever LoB item you’re working with). A successful install should result in the following page when you navigate to https://localhost:8080/BAService/ManagementService.svc/
Step 3: Creating a sample stored procedure For this sample, I’m working with a SQL Server database running in a VM behind Tallan’s firewall. I did not have to do any special firewall configuration for the VM, my host machine, or IT to get this up and running, nor did I have to make use of any kind of tricky proxying methods. In my database (named BTSTrainDb, a database I have for testing and samples), I created a table: dbo.sn. This table has an ID column, a varchar SerialNumber column, and a bit IsValid column. I also created a simple stored procedure that takes a varchar as a parameter and uses it to do a look up on the dbo.sn table:
USE [BTSTrainDb] GO
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[sn]( [ID] [int] IDENTITY(1,1) NOT NULL, [SerialNumber] [varchar](50) NOT NULL, [IsValid] [bit] NOT NULL ) ON [PRIMARY] GO SET IDENTITY_INSERT dbo.sn ON GO INSERT INTO [dbo].[sn] (SerialNumber, IsValid) VALUES ('asdf', 1), ('fdsa', 0), ('test', 1);' GO SET IDENTITY_INSERT dbo.sn OFF GO
CREATE PROCEDURE [dbo].[usp_ValidateSN] ( @sn varchar(50) ) AS BEGIN SET NOCOUNT ON;
SELECT IsValid from dbo.sn WHERE SerialNumber = @sn; END
Obviously, this procedure could contain any amount of business logic and/or perform other CRUD operations if desired. I also have a SQL user that has permissions on the database, table, and stored procedure. Step 4: Create a ServiceBus relay with an ACS namespace Microsoft has recently removed the ability to do this from the management portal, and so it has to be done through a PowerShell cmdlet. On top of that, the current documentation for this command is out of date! Cesar Cordero (a colleague here at Tallan) just recently wrote a blog about this with some more details here: http://blog.tallan.com/2014/11/06/service-bus-authentication-and-authorization/ Here’s an overview of what you need to do:
- Get the Azure PowerShell module(s) if you don’t already have them: http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell/
- Add-AzureAccount; follow the steps in the dialog that pops up
- Select-AzureSubscription (if your account is associated with more than one subscription; this information can be found by clicking on the “Subscriptons” button near your username at the top of the Azure Portal)
- New-AzureSBNamespace -Name <name> -Location “Eastern US”; at the prompt for NamespaceType, type Messaging. Note: The name of this namespace must be different from the name of the BizTalk service. If it is not, there will be a clash between the ACS namespace used for the BizTalk Services ACS and the ServiceBus ACS.
- You can now retrieve the connection information for this ServiceBus namespace from the management portal (or copy it from the output of the PowerShell cmdlet). I made a note of it as it’s required for configuration in step 5.
Step 5: Create the LoB relay Open Visual Studio. In the Server Explorer, right click on BizTalk Adapter Services, and select Add a BizTalk Adapter Service. Enter the URL set up in step 2 (https://localhost:8080/BAService/ManagementService.svc/). Expand the newly created adapter service. You will be prompted to enter ACS information; enter the information for the BizTalk Adapater Service ACS from Step 1. Right click on SQL, and click “Add a Target”. For connection parameters, fill in the server information
Operations should look familiar to anyone who’s used the WCF SQL binding. Go to Strongly-Typed Procedures and add the dbo.usp_ValidateSN:
Choose your runtime security. Here, I entered the username that has access to the procedures and its password as a Fixed username:
Specify the LOB Relay URL using your newly created service bus namespace; for LOB Relay path, choose something that will be memorable this particular SQL relay path, and for the sub-path choose a unique identifier (like the InboundID parameter for WCF SQL binding in on prem BizTalk):
Review your information on the next page and click create. Step 6: Create an EAI Bridge for this relay In Visual Studio, create a new BizTalk Service project (Under Visual C#). Right click on your new LOB SQL type and click “Add schemas to <ProjectName>”; enter the project folder and filename prefix you want, and enter the credentials you set up in the previous step under runtime security. This will generate two schemas that should look pretty familiar if you’ve used WCF SQL before. Drag the LOB SQL type over onto your design surface (named MessageFlowItnerary.bcs by default). Drag an XML Request-Reply bridge onto the surface from the toolbox. Drag a connector between the two. On the connector, set the following properties: Filter Condition: Match All (will set to 1=1): this sets the connector to always send messages through; we’ll cover content routing in the next article in this series
Route Action: configure as follows (again, this should look familiar!): this sets the SOAP action header
Your surface should look like this now (after renaming the XML bridge to SQLRequest):
Double click the SQL LOB icon (circled). In the config file that pops up, edit the sharedSecret node with the information from your ServiceBus relay ACS (not BizTalk Services ACS):
Build and deploy the solution (you’ll be prompted for your BizTalk Services ACS information on deployment). This operation should not require a refresh of the service, but go ahead and select it anyway. Grab the MessageSender app: https://code.msdn.microsoft.com/windowsazure/Windows-Azure-BizTalk-EAI-af9bc99f. Build it and run the following command with a generated instance of the request schema:
messagesender.exe <BizTalk Service Namespace Name> owner <BizTalk Service ACS Key> https://<name>.biztalk.windows.net/default/SQLRequest <instance of the request schema.xml> application/xml
A sample request message looks like this:
<ns0:usp_ValidateSN xmlns:ns0="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo"> <ns0:sn>asdf</ns0:sn> </ns0:usp_ValidateSN>
And here’s the successful output:
Stay tuned for part 2!