Creating the Sending and Receiving Applications

BizTalk Messaging is now ready to receive a document of a specific type from an application, transform it into another format, and pass it along to another application.

Now we need to modify and create the following three applications:

  • Create an ASP application that will send the document from Sunset Bank, Inc., to Big Bank Co, sendTrans.asp.

  • Modify the Big Bank Co.'s HTTP receive ASP page to receive the document coming from Sunset Bank, Inc., and submit it to BizTalk, receiveTrans.asp.

  • Create the application that will receive the final document from BizTalk and process it according to ordinary business rules, getTrans.asp.

Working with the Code—sendTrans.asp

Let's begin. First, develop the ASP file that will send the XML file from Sunset Bank, Inc., to Big Bank Co. Call this ASP sendTrans.asp (see Listing 7.4).

Listing 7.4. sendTrans.asp
  <%@ Language = "JavaScript" %>
  <%
  var xDoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0");
  xDoc.async = false;
  xDoc.load (Server.MapPath("../documents/sunsetbankinstance.xml"));
  var xHttp = Server.CreateObject("Msxml2.XMLHTTP");
  xHttp.open ("POST", "http://localhost/BigBank_Co/application_ /receiveTrans.asp", false);
  xHttp.send (xDoc.xml);
  Response.Write (xHttp.responseText);
%>

Save this file to your application folder under SunsetBank_Inc, in your wwwroot directory—for example, c:inetpubwwwrootSunsetBank_IncapplicationsendTrans.asp. The primary purpose of this ASP file is to load an XML file representing financial data about transactions that occurred on a given day and submitting them via HTTP to an ASP file at Big Bank Co. In this application, the line, xDoc.load (Server.MapPath("../documents/sunsetbankinstance.xml"));loads the XML transaction (which will be reviewed next and can be manipulated in Notepad), whereas lines, xHttp.open ("POST", "http://localhost/BigBank_Co/application/receiveTrans.asp", false); and xHttp.send (xDoc.xml); are responsible for actually sending the document. The line, Response.Write (xHttp.responseText); asks that the response be sent back to the client with information regarding the success or failure of the transmission.

You need to save the following XML file as shown in Listing 7.5 to the documents folder under SunsetBanks_Inc. This document, again, represents the actual data that you will be submitting to BizTalk Server. It can be manipulated in Notepad, if you want to manipulate the names, ids, account numbers, and so on. It is a basic syntax, but hopefully detailed enough to help you understand the inner workings of BizTalk.

Listing 7.5. SunSetInstance.xml
<?xml version="1.0" encoding="utf-8" ?>
<Transactions>
<Transaction id="ABC-008">
<Account name="Jason Jones" number="159599" />
<Amount>-51.50</Amount>
<Type>ATM</Type>
<Facility>Sunset Bank, East</Facility>
<Location>
<Name>Sunset Bank</Name>
<Address>12121 Walker Dr., VA 55555</Address>
</Location>
</Transaction>
<Transaction id="ABC-009">
<Account name="Jane Smith" number="177589" />
<Amount>-12.50</Amount>
<Type>ATM</Type>
<Facility>Sunset Bank, East</Facility>
<Location>
<Name>Sunset Bank</Name>
<Address>12121 Walker Dr., VA 55555</Address>
</Location>
</Transaction>
</Transactions>

Again, the purpose of this document is simply to act as a data stream that will be sent from Sunset Bank to Big Bank.

Working with the Code—receiveTrans.asp

Now that we have an application that is sending data in XML to Big Bank, Inc., we need to modify the BizTalk HTTP receive ASP page that receives the data and submits it to BizTalk Server. This page ships with BizTalk and can be modified for each of our member banks. Listing 7.6 shows the code.

Listing 7.6. receiveTrans.asp
 <%@ Language = "JavaScript" %>
 <%
 var xmlTrans = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0");
 xmlTrans.async = false;
 xmlTrans.load (Request);
 var strTrans = String(xmlTrans.xml);
 var objInterchange = Server.CreateObject("BizTalk.Interchange");
 var strOpenType = "BIZTALK_OPENNESS_TYPE_NOTOPEN";
 var strHandle = objInterchange.submit (1, strTrans, "", "", "", +
     + "", "", "Transaction from SunsetBank_Inc to BigBank_Co via HTTP");
Response.Write ("Success: " + strHandle);
 %>

Save this file to your application folder under BigBank_Co, in your wwwroot directory—for example, c:inetpubwwwrootBigBank_COapplication eceiveTrans.asp.

In receiveTrans.asp, at line, xmlTrans.load (Request);, the XML document sent from sendTrans.asp is loaded into the DOM. The goal at this point is simply to take this XML and submit it to BizTalk. This occurs at the var strHandle = objInterchange. submit (1, strTrans, "", "", "", + + "", "", "Transaction from SunsetBank_ Inc to BigBank_Co via HTTP"); line. However, let's first look at the var objInterchange = Server.CreateObject("BizTalk.Interchange"); line. Here we instantiate the BizTalk.Interchange object, which allows us to use a submit method to exchange documents with BizTalk Server. When we call the submit method, we have to supply a few parameters.

First is the BIZTALK_OPENNESS_TYPE enumeration. This value indicates whether the associated BizTalkChannel or Port objects are open. The enumeration values for the parameter are

  • BIZTALK_OPENNESS_TYPE_NOTOPEN— This specifies that the instance of the BizTalkPort is not open.

  • BIZTALK_OPENNESS_TYPE_SOURCE— Indicates that the source organization of the BizTalkPort is open.

  • BIZTALK_OPENNESS_TYPE_DESTINATION— Specifies that the destination organization of this instance of the BizTalkPort is open.

In this case, we are passing the parameter that tells BizTalk Server that the associated BizTalkPorts cannot open. The next parameter represents the XML document as a string. This is the literal data that BizTalk has to preserve and pass along to the waiting application. Finally, we pass the name of the channel that processes the document. And that's it! From this point on, BizTalk Server handles the rest.

Of course, you can do more with this object, but this shows how easy it can be to get BizTalk working almost immediately in a B2B or A2A type solution.

This completes our assignment for getting data into BizTalk, and we have configured BizTalk to transform the data. Now we need to see how to get information out of BizTalk. It's really simple—which is the best part about all this.

Working with the Code—getTrans.asp

The final step in the application is to show you how to get data out of BizTalk and into your application. Listing 7.7 shows the code.

Listing 7.7. getTrans.asp
<%@ Language = "JavaScript" %>
<%
var xRequest = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0");
xRequest.async = false;
xRequest.load (Request);
xRequest.save (Server.MapPath("../documents/test.xml"));
%>

Save this file to your application folder under BigBank_Co, in your wwwroot directory—for example, c:inetpubwwwrootBigBank_COapplicationgetTrans. asp.

To run the application, browse to and run the c:inetpubwwwrootSunSetBank_IncapplicationsendTrans.asp page using an Internet browser. If the application runs successfully, you should see an XML document named text.xml in the directory c:inetpubwwwrootBigBank_COdocuments.

That's it. Again, you can make this infinitely more complex if you want, but the great part about this is its simplicity. All the files we are working with are even in the same working directory.

All we do here is accept the request object and the XML data and load it into the DOM. From this point on, we could

  • Load the data into a SQL database.

  • Parse out particular pieces of the XML, submit them in an e-mail to management, and save all the XML to the file system.

  • Parse out the XML and send parts to another application, while saving the rest to a database.

Of course, all we are doing in Line 6 is saving the XML to the file server, but the possibilities are endless.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset