|
Chapter 11: Automating Electronic Procurement
Chapter 11 Automating Electronic Procurement
ScenarioThis scenario represents a business situation in which your company is purchasing products from several different suppliers. We will focus on setting up a business solution by using Microsoft BizTalk Server 2002 to automate the procurement process that takes place between your company and its suppliers over the Internet. We call this solution e-procurement.In this scenario you set up a purchasing hub for your company. The hub handles all the inbound and outbound documents that are exchanged between your company and the suppliers. For the purposes of this scenario, a business transaction between your hub and the suppliers uses four different documents. A transaction starts when a purchase order (PO) is sent from the hub to the supplier. Upon receipt of the PO, the supplier generates an invoice for that PO, which is returned to the hub. When the hub receives an invoice for an outstanding PO, the hub sends a payment to the supplier. Finally, the supplier sends a payment acknowledgement to the hub and the e-procurement transaction is complete. The following illustration shows the business transaction used in this sample. E-procurement scenario data flow The documents in this transaction are transmitted to their destinations over the Internet by using XML Web services created with Microsoft Visual Studio .NET. All of the custom components used in this scenario are written in the Microsoft Visual C# .NET (C sharp) programming language.
SolutionMicrosoft BizTalk Server 2002 provides a rich set of features to use in implementing an automated e-procurement system. On both the hub and the supplier systems, BizTalk Server XLANG schedules are used to implement the business processes and logic required to complete a business transaction.The following topics describe the flow of documents through both systems, as shown in the preceding illustration.
The following topics describe how BizTalk Server 2002 features are used in this scenario:
Hub: Send Purchase Order to SupplierThe following illustration shows the purchase order flow through the hub system.Hub system initiates a business transaction A business transaction is initiated when the ordering application generates a purchase order (PO) named PO.xml, and delivers it to the receivepo message queue, which is monitored by the Receive PO receive function. The document is submitted to a BizTalk Messaging Services channel configured for PO processing. The HubReceivePO messaging port activates a new instance of the XLANG schedule Hub.skx, and then delivers the document to the ReceivePO port on that XLANG schedule. The schedule contains some business logic to apply a simple approval process to the purchase order. For this scenario, the purchase order is automatically approved if the total value is less than $1,000.00. If the PO.xml document is approved, it is sent to the HubSendPO channel for further processing. When the processing completes and the correlation information is written to a database, the purchase order is sent to the supplier by means of an application integration component (AIC) that functions as a client to the supplier's XML Web service.
Supplier: Receive PO and Send Invoice to HubThe following illustration shows the incoming purchase order and the resulting invoice flow through the supplier system.Supplier system receives a purchase order and sends back an invoice The supplier's XML Web service accepts the incoming purchase order. The XML Web service submits the PO to a BizTalk Messaging Services channel configured for PO processing. The SupplierReceivePO messaging port then activates a new instance of the XLANG schedule Supplier.skx, and delivers the document to the ReceivePOfromHub port on that XLANG schedule. The schedule contains some business logic to apply a simple approval process to the purchase order. For this scenario, the purchase order is automatically rejected if the total value is less than $300.00. If the PO.xml document is approved, it is sent to a component that transforms the purchase order into an invoice document. Then the invoice is sent to the SupplierSendInvoice channel for further processing. When the processing completes and the correlation information is written to a database, the invoice is sent back to the hub by means of an AIC that functions as a client to the hub's XML Web service.
Hub: Receive Invoice and Send Payment to SupplierThe following illustration shows the invoice and the resulting payment flow through the hub system.Hub system receives an invoice and sends back a payment The hub's XML Web service accepts the incoming invoice. The XML Web service submits the invoice to a BizTalk Messaging Services channel configured for invoice processing. Then the pipeline component on that channel correlates the incoming document with an XLANG schedule instance identifier. This correlation information is obtained by reading the key-pair values from the custom correlation database. The invoice is sent to the correlated XLANG schedule instance, and resumes processing on the ReceiveInvoice port. After the document is back in the schedule, it is sent to a component that transforms the invoice into a payment. The payment is sent to the HubSendPayment channel for further processing. When the processing completes, the payment is sent to the supplier by means of an AIC that functions as a client to the supplier's XML Web service.
Supplier: Receive Payment and Send Acknowledgement to HubThe following illustration shows the payment and the resulting acknowledgement flow through the supplier system.Supplier system receives a payment and sends back an acknowledgement The supplier's XML Web service accepts the incoming payment for the invoice that it issued. The XML Web service submits the payment to a BizTalk Messaging Services channel configured for payment processing. Then the pipeline component on that channel correlates the incoming document with an XLANG schedule instance identifier. This correlation information is obtained by reading the key-pair values from the supplier custom correlation database. The payment is sent to the correlated XLANG schedule instance, and resumes processing on the ReceivePayment port. After the document is back in the schedule, it is sent to a component that transforms the payment into a payment acknowledgement. The payment acknowledgement is sent to the SupplierSendPaymentAck channel for further processing. When the processing completes, the payment acknowledgement is sent back to the hub by means of an AIC that functions as a client to the hub's XML Web service. At this point, the supplier XLANG schedule for this transaction completes. The XLANG schedule instance on the hub system completes after it receives the payment acknowledgement, correlates it to the correct purchase order, and writes the acknowledgement document to the folder \Microsoft .NET Server Solutions for the Enterprise\E-Procurement\Application\eprocurement\PaymentAckReceived.
XLANG Schedule ActivationBizTalk Server messaging ports activate the XLANG schedules used in this scenario. However, the first actions within the schedules are bound to Message Queuing shapes, rather than BizTalk Messaging shapes, so that per-instance message queues are not created. This helps to optimize the performance of the schedule by preventing the creation, and subsequent deletion, of a message queue used only for initiating the schedule. The following illustration shows the hub XLANG schedule drawing.
E-Procurement XLANG Schedule CorrelationThis scenario uses two databases to store and retrieve information that correlates the documents exchanged in a business transaction to the correct XLANG schedule instances. Without this mechanism, documents would not be properly synchronized when multiple orders are processed simultaneously. This could result in a payment being issued on the wrong invoice. One database exists on the hub system to correlate the documents processed by the Hub.skx XLANG schedule, and one database exists on the supplier system for documents processed by the Supplier.skx XLANG schedule. The BizTalk Server channel called by the XLANG schedules uses a custom pipeline component to save and recall correlation information in these databases. The correlation information consists of two parts:
The XLANG Scheduler Engine automatically generates the XLANG schedule GUID when the XLANG schedule begins. The TransactionID is a unique identifier contained within a specific document instance, such as a purchase order number or invoice number. The hub TransactionID for a purchase order is obtained from the Number field on the hub ordering application. The user can modify this value before submitting a purchase order. By contrast, the supplier TransactionID for an invoice is automatically generated by the SQL Server stored procedure usp_InsertCorrInfo that is associated with the SupplierCustomCorrelation database. Storing the Correlation Information In this scenario, when the hub receives a new purchase order from the ordering application, the GUID of the XLANG schedule is extracted and stored in the CustomCorrelation database along with the PO number as a TransactionID. When the supplier receives the purchase order and activates an XLANG schedule of its own, the GUID of the supplier's XLANG schedule is stored along with the invoice number as the TransactionID. The supplier system stores this pair of values in its own SupplierCustomCorrelation database. These initial correlation values are used to associate the remaining incoming and outgoing documents to the correct running XLANG schedule instance as the transaction progresses until the XLANG schedule completes. Reading the Correlation Information The correlation of a document to its running XLANG schedule instance begins when the hub receives an invoice associated with a purchase order. At this point, BizTalk Server queries the invoice for the TransactionID (PO number) and looks up the associated XLANG schedule GUID in the CustomCorrelation database. The invoice document is passed to the Hub.skx schedule instance that matches the GUID, and the schedule continues running. Similarly, when the supplier receives a payment from the hub, BizTalk Server queries the payment for the TransactionID (invoice number) and looks up the associated XLANG schedule GUID in the SupplierCustomCorrelation database. The payment document is passed to the Supplier.skx schedule instance that matches the GUID, and the schedule continues running. Finally, when the hub receives the payment acknowledgement, BizTalk Server queries the acknowledgement for the TransactionID (PO number) and looks up the associated XLANG schedule GUID in the CustomCorrelation database. The payment acknowledgement is passed to the Hub.skx schedule instance that matches the GUID, and the schedule continues running.
Tools and TechnologiesThis section describes the hardware and software requirements for running the e-procurement sample included on the CD-ROM provided with this book.
Hardware and Software RequirementsThis sample assumes that you have the following installed on the computer that is running BizTalk Server:
Using Microsoft Visual Studio .NETThe components and XML Web services used in the e-procurement scenario were created by using Microsoft Visual Studio .NET. These components and services use a set of primary interop assemblies (PIAs) to access the COM-based BizTalk Server 2002 application programming interfaces (APIs).For more information about using PIAs to access any BizTalk Server 2002 API from managed code, download the BizTalk Server 2002 Toolkit for Microsoft .NET from the Microsoft Developer Network. Creating XML Web Services This section contains information about creating the XML Web services used in this scenario. These XML Web services provide a mechanism for accepting incoming documents through SOAP. The documents are sent from a client to the host running an XML Web service. The client obtains a reference, also called a proxy, to the remote host by specifying the URL of the XML Web service. After the proxy is established, the client can use the methods provided by the XML Web service. In this scenario, the BizTalk messaging ports contain an application integration component (AIC) that uses a proxy to the appropriate remote XML Web service method call. For example, the messaging port on the supplier system that sends an invoice contains an AIC with a proxy to the XML Web service method Process_invoice(invoice) provided by the hub system. Note that the invoice argument passed to the method represents a strongly typed object corresponding to the CommonInvoice.xml document schema. The XML Web services provide methods to accept a specific document type, such as a purchase order or invoice, and submit that document directly to a BizTalk Server 2002 channel for further processing. Converting a BizTalk Document to a C# Class For every document that is passed to an XML Web service, you need to create a corresponding C# class. The following steps illustrate this process:
The Retrieve from WebDAV dialog box appears.
The Export XSD Schema dialog box appears.
The Visual Studio .NET Command Prompt window appears.
XSD filename.xsd /c This command creates a new C# class named filename.cs.
namespace namespacename {
For example, using the following output:
/// <remarks/>
[WebMethod]
At this point, the client program can add a reference to the XML Web service method that you just created. This allows you to call the XML Web service from an application integration component (AIC), which is bound to a BizTalk Server messaging port. As a result, BizTalk Server can process a document and then deliver it directly to the XML Web service. Calling an XML Web Service from an AIC This section describes the steps required for an AIC to call an XML Web service. Update the resource file Create a C# class project in Microsoft Visual Studio .NET for the AIC that calls the XML Web service. View the Reference.cs file to ensure that the XMLRoot information contained in this class is correct, and that the structure matches the class in the original .cs file created for the XML Web service. To view and update the Reference.cs file
The root element appears as:
[System.Xml.Serialization.XmlAttribute("Namespace=http://tempuri.org")]
[System.Xml.Serialization.XmlRoot("RootElementName")]Where RootElementName is the name of the document's root element.
Add a reference to the XML Web service The AIC project must contain a reference to access the XML Web service remotely. After this reference is made, the project acts as a client to that XML Web service. For example:
// Reference to the hub XML Web service Implement the IBTSAppIntegration.ProcessMessage method To indicate that the project is an AIC, the code must implement the ProcessMessage method on the IBTSAppIntegration interface. The following example is from the supplier's client code that sends an invoice to the hub XML Web service:
string IBTSAppIntegration.ProcessMessage(string strDocument)
Register the AIC for use with COM When creating your AIC project in Microsoft Visual Studio .NET, you might want to use a fixed GUID value to maintain binary compatibility. Otherwise, the GUID for the component changes every time you compile the code. In that case, any references to this component would have to be rebound in your XLANG schedules. The following procedure assigns a static GUID value to the component and registers the AIC for COM interoperability:
using System.Runtime.InteropServices;
[Guid("")]
The Create GUID dialog box appears.
The project Property Pages dialog box appears.
Summary In this section, you learned how to use Microsoft Visual Studio .NET to:
All of the source code for the examples in this section is included on the CD-ROM provided with this book. To view the source code, open the file \Microsoft .NET Server Solutions for the Enterprise\E-Procurement\Application\eprocurement\Build_everything.sln. The next section explains how to configure and run the e-procurement sample.
ImplementationBefore you can run the e-procurement sample, you must register components, attach the correlation databases, and configure the BizTalk Messaging objects on the hub and supplier systems. In this scenario, both the hub and the supplier are configured on one BizTalk Server installation. In an actual production environment, the hub and the supplier would be two separate entities connected to the Internet.
Preliminary SetupThe steps in this section explain how to configure your system to run the e-procurement sample provided on the CD-ROM that accompanies this book. After you run the CD-ROM setup, the e-procurement sample is located on the installation drive in the folder \Microsoft .NET Server Solutions for the Enterprise\E-Procurement.
Update the Global Assembly Cache The primary interop assemblies required for BizTalk Server 2002 must be added to your Microsoft .NET global assembly cache (GAC). This provides a single access location for components using the assemblies, so that multiple local copies of the assemblies are not required. To update the GAC with the BizTalk Server 2002 assemblies, run the following script: \Microsoft .NET Server Solutions for the Enterprise\E-Procurement\Application\setup_eproc.cmd Attach the SQL Server 2000 Databases In this procedure you set up the correlation databases that are used with the e-procurement sample. You should use these instructions if you are using Microsoft SQL Server 2000 in your BizTalk Server installation. If you are using Microsoft SQL Server 7.0, use the instructions in the following topic titled "Create the SQL Server 7.0 Databases" instead of this one. The following instructions assume that SQL Server 2000 is installed on the same computer as BizTalk Server. If SQL Server is installed on a different computer, you will need to modify these instructions so that they will work in your environment. The hub database files (CustomCorrelation_Data.*) are located in the \Microsoft .NET Server Solutions for the Enterprise\E-Procurement\Application\eprocurement\hub_database folder, and the supplier database files (SupplierCustomCorrelation_Data.*) are located in the \Microsoft .NET Server Solutions for the Enterprise\E-Procurement\Application\eprocurement\supplier_database folder.
The SQL Server Enterprise Manager appears.
The Attach Database dialog box appears.
The Browse For Existing File dialog box appears.
A message box appears indicating that the process was successful.
Create the SQL Server 7.0 Databases You should use the following procedure if you are using Microsoft SQL Server 7.0 in your BizTalk Server installation. If you are using Microsoft SQL Server 2000, use the instructions in the preceding topic titled "Attach the SQL Server 2000 Databases" instead of this one.
The SQL Server Enterprise Manager appears.
The Database Properties menu appears.
The Database Properties menu appears.
The Connect to SQL Server menu appears.
This will process the CustomCorrelationTable.sql file. If the SQL file has been run, you will see a message stating: The command(s) completed successfully.
Configure BizTalk Messaging Services In this procedure you run the setup application to configure the BizTalk Messaging Services for the hub and the supplier to run the e-procurement sample. The e-procurement setup application performs the following tasks:
.\private$\receiveinvoice .\private$\receivepayment .\private$\receivepaymentack .\private$\receivepo .\private$\receivepo2 .\private$\supplierreceivepo .\private$\supplierreceivepo2 .\private$\status
The queues are used to transfer data between the business partners represented by the running hub and supplier XLANG schedules. The status queue is used to provide dynamic updates to the application used to submit orders from the hub.
Each channel is configured to override the messaging port default values and associate the message with a specific XLANG schedule instance by using the message label.
Prior to running the setup application, verify that none of the message queues listed above exist. If any of these queues exist, the e-procurement sample setup might fail. To set up the e-procurement sample
A setup dialog box appears.
A status field in the dialog box displays the progress of the setup until it completes.
Running the E-Procurement SampleThe e-procurement sample demonstrates how to exchange documents through XML Web services and correlate user-defined fields in an XLANG schedule. This sample allows you to use a data value that uniquely identifies a document, such as a purchase order number, and associate that identifier with a running XLANG schedule instance to process a document through the steps of a business transaction.To run this sample
The XLANG Event Monitor appears. Running the XLANG Event Monitor allows you to view the progress of the hub and supplier XLANG schedules as they progress through the transaction. This is an optional step.
The Hub Order Application appears.
An order is submitted to the e-procurement system, and the progress of the order is displayed in the Document processing status area.
If you are using the XLANG Event Monitor to view the schedules, the hub schedule appears first in the folder of running schedules, followed by the supplier schedule. Eventually, the supplier schedule finishes and moves to the completed folder, followed by the hub schedule. To run the sample and have the purchase order denied on the hub, change the purchase order Amount field to a value greater than $1000.00. To run the sample and have the purchase order denied by the supplier system, change the purchase order Amount field to a value less than $300.00.
Uninstalling the E-Procurement SampleA script is not provided to remove the files and BizTalk Messaging Configuration objects, such as messaging ports and channels, that are created by running the setup application. The following list contains the BizTalk Messaging Configuration objects, files, folders, and libraries used by this sample. These can be manually deleted when you are finished running the sample.Channels HubReceivePO, HubSendPO, SupplierReceivePO, HubReceiveInvoice, SupplierSendInvoice, HubSendPayment, SupplierReceivePayment, SupplierSendPaymentAck, HubReceivePaymentAck, HubSendPayAckToFile Messaging ports HubReceivePO, HubSendPO, SupplierReceivePO, HubReceiveInvoice, SupplierSendInvoice, HubSendPayment, SupplierReceivePayment, SupplierSendPaymentAck, HubReceivePaymentAck, HubSendPayAckToFile Organizations Hub, Supplier Document definitions ECommonInvoice, ECommonPayment, ECommonPO, EPaymentAck, EStatus Receive functions Receive PO Private messaging queues receiveinvoice, receivepayment, receivepaymentack, receivepo, receivepo2, supplierreceivepo, supplierreceivepo2, status BizTalk Server repository files (WebDAV) ECommonInvoice.xml, eCommonPayment.xml, ECommonPO.xml, ePaymentAck.xml, eStatus.xml Registered libraries db_common.dll, hub_send_payment.dll, hub_send_po.dll, hub_comps.dll, hub_correlation.dll, supp_send_invoice.dll, supp_send_payack.dll, supp_comps.dll, supplier_correlation.dll Primary Interop Assemblies BTSComponentsLib.dll, BTSInterchangeLib.dll, MSCSCoreLib.dll, PipeCompLib.dll XML Web services E_Proc_Hub_WS, E_Proc_Supplier_WS
Additional InformationThis section provides additional resource information.Microsoft BizTalk Server 2002
Microsoft SQL Server
Microsoft Message Queuing Message Queuing Web site http://www.microsoft.com/msmq/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||