| By Thomas Abraham | Article Rating: |
|
| August 19, 2008 10:15 AM EDT | Reads: |
4,946 |
Now we need to define the operations (methods) on our service. For this example we will create only two operations: RecordTransaction, which can either add or remove funds from an account, and GetCustomer, which can retrieve a very basic set of customer data. The operations will use a request/response pattern, which simply means that they will take in one set of data and return another set of data. The structure of the data in and out will be defined as request and response "messages" which, again, are defined in XML Schema.
We will define the four following message schemas:
- RecordTransactionRequestMessage
- RecordTransactionResponseMessage
- GetCustomerRequestMessage
- GetCustomerResponseMessage
A message schema may contain any mix of data necessary to carry out an operation. It may contain instances of complex entity schemas, such as Customer or Account, in addition to other elements with simple data types, like strings and integers.
The general process for creating these schemas is the same as for the Customer and Account schemas created in Step 2, so please refer back to those steps to create the following schemas and child field elements and convert them to reusable types.
In our simple example shown in Table 1, the RecordTransaction operation takes in an account ID, a customer ID, and an amount. It will return a confirmation number. The request and response messages in this case use only simple string and decimal types.
The GetCustomer operation takes in only a customer ID, but returns more complex data. The GetCustomerResponseMessage schema isn't done yet, because we want to return a complete Customer element. First, we must import the definition of Customer from the Customer.xsd file, and then create a new node that references the Customer type.
- Open GetCustomerResponseMessage.xsd in the BizTalk Editor by double-clicking it in the Solution Explorer window
- Select the top-most node in the tree called "<Schema>" then locate the "Imports" property in the Properties window. Click the "..." button in the property value textbox to open the Imports dialog box.
- In this case the Customer schema uses a different target namespace than the GetCustomerResponseMessage schema, which means in XML Schema terms that we will "import" the other schema. (We would "include" if both shared the same target namespace.) Ensure that "XSD Import" is selected in the "Import new schema as" combo box.
- Click the Add button then expand the BankAccountService and Schemas tree nodes to expose the list of schemas in the current project. Select "BankAccountService.Customer" and click the OK button.
- Note that the Imports dialog now lists a reference to the Customer.xsd file. A default namespace prefix of "ns0" has been automatically assigned to the reference. Each type reference in the current schema to the Customer schema must be prefixed by "ns0." Click the OK button to close the Imports dialog box.
- Now, create a new node by right-clicking the GetCustomerResponseMessage node and choosing the "Insert Schema Node", "Child Record" menu item. Change its name to "Customer" and press Enter.
- Ensure that the Customer node is selected and locate the "Data Structure Type" property in the Properties window. Select "ns0:Customer (Reference)" from the list. Notice that "ns0:Customer (ComplexType)" is also an option, and that will work fine too. The difference is an XML Schema subtlety: Reference defines the Customer node in the source type's namespace, while ComplexType defines the Customer node in the current schema's namespace.
- The newly created Customer node is now defined as a complete instance of the Customer type.
At this point our contract is complete! We have defined Account and Customer structures, identified the service operations, and defined message structures for each operation's request and response. Before we continue, build the solution, and verify that the build was successful.
Step 4: Create simple orchestrations to carry out the service operations
With the contract in place, we're ready to build out the back-end of the service. Given the simple nature of this demonstration, we're going to keep the implementation as simple as possible using hard-coded values and faking the operations. We will create two orchestrations to match our two operations.
- With the BankAccountService solution open, right-click the BankAccountService project and choose the Add menu then "New Item..." Select the "Orchestration Files" tree node and then the "BizTalk Orchestration" item in the right-hand pane. Type the name "GetCustomer.odx" in the Name textbox then click the Add button to create the schema file. The orchestration should open in the Orchestration editor.
- First, we will add a port (a communication point into or out of BizTalk) that corresponds to the GetCustomer operation on our service interface. Open the Toolbox window and drag a "Port" shape onto the orchestration surface. The Port Configuration Wizard will open.
- Click the Next button to bypass the first page of the wizard. Type "GetCustomerPort" into the Name textbox then click the Next button.
- On the "Select a Port Type" page, leave the default selection of "Create a new Port Type" and type "GetCustomerPortType" into the "Port Type Name" textbox. Select the "Request-Response" radio button then click the Next button twice and the Finish button to complete the wizard.
- Now we'll configure the port to use the GetCustomerRequestMessage and GetCustomerResponseMessage schemas to receive and send data. Locate the "Orchestration View" window and then the "Port Types," "GetCustomerPortType" tree node. Expand the node to display the Operation_1 node. Select the Operation_1 node and press F2 to enter edit mode. Type the new name "GetCustomer" and press Enter.
- Next, expand the "GetCustomer" node to display the "Request" and "Response" nodes. Select the "Request" node then locate the "Message Type" property in the Properties window. In the "Message Type" value, expand the drop-down list and then expand the Schemas tree node. Locate and select the "BankAccountService.GetCustomerRequestMessage" schema.
- Now, select the "Response" node in the "Orchestration View" and repeat the process in Step 6 to select the "BankAccountService.GetCustomerResponseMessage" schema.
- The port definition is now complete, but we need to configure the orchestration to receive data from and send data to the port. From the Toolbox, drag a "Receive" shape just below the green circle on the orchestration surface. Next, drag the green chevron icon labeled "Request" on the "GetCustomerPort" shape to the "Receive_1" shape. The designer will display a line between the port and the "Receive_1" shape.
- The next step is the Send side. Follow the same pattern in Step 8 to add a "Send" shape just above the red circle, and drag a connection between the send shape and the port's "Response" icon.
- We want the orchestration to start as soon as our service receives a message, so select the "Receive_1" shape and locate the "Activate" property in the Properties window. Set the value to "True."
- Now we'll take a major shortcut to build a dummy GetCustomerResponseMessage message in between the "Receive_1" and "Send_1" shapes. From the Toolbox, drag a "Message Assignment" shape directly after the "Receive_1" shape. Next, select the "ConstructMessage_1" shape. Locate the "Messages Constructed" property in the Properties window. In the value textbox, open the drop-down list and check the box next to "Message_2." Message_2 is a message of type GetCustomerResponseMessage, which BizTalk created for us when we connected the "Send_1" shape earlier.
- Create a variable of type System.Xml.XmlDocument by right-clicking the "Variables" tree node in the "Orchestration View" window and choosing "New Variable." Locate the "Type" property in the Properties window, and in the value textbox, select "<.NET Class...>" from the drop-down list. Locate and select XmlDocument in the right-hand list view then click the OK button.
- Next, locate the "MessageAssignment_1" shape and double-click it to open the Expression Editor. Paste in the following text, then click OK:
Variable_1.LoadXml(@"<ns0:GetCustomerResponse
Message xmlns:ns0=""http://BankAccountService.GetCustomerResponseMessage"">
<ns1:Customer xmlns:ns1=""http://BankAccountService.Customer""><CustomerID>12345</CustomerID>
<LastName>Smith</Last
Name></ns1:Customer></ns0:GetCustomerResponse
Message>");
Message_2 = Variable_1;
Published August 19, 2008 Reads 4,946
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Thomas Abraham
Thomas Abraham, MCPD, MCT, is an Enterprise Consultant with Minneapolis, MN-based management and technology consulting firm Digineer (www.digineer.com). Thomas maintains a blog at http://blogs.digineer.com/blogs/tabraham.
- The Top 150 Players in Cloud Computing
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- Industry Experts Discuss the State of Cloud Computing
- Cloud Expo New York Call for Papers Deadline December 15
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- US Federal Government is Major Cloud Computing Innovator
- Google Wave
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Adaptivity & Cloud Computing: Exclusive Q&A with CEO Tony Bishop
- 4th International Cloud Expo: Photo Album
- The Top 150 Players in Cloud Computing
- SYS-CON.TV: Cloud Computing Expo Power Panel
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- 1st Annual GovIT Expo: Letter from the Technical Chair
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- Industry Experts Discuss the State of Cloud Computing
- SOA World Power Panel on SYS-CON.TV
- CIA was Headed to an Enterprise Cloud All Along: Jill Tummler Singer
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Cloud Expo New York Call for Papers Deadline December 15
- Stock in Focus: Dragon Capital
- The i-Technology Right Stuff
- Who Are The All-Time Heroes of i-Technology?
- Get the Message
- Where Are RIA Technologies Headed in 2008?
- i-Technology Viewpoint: Is Web 2.0 the Global SOA?
- i-Technology Viewpoint: Thinking Outside the VC Box
- ESB Myth Busters: 10 Enterprise Service Bus Myths Debunked
- i-Technology Viewpoint: When to Leave Your First IT Job
- SOA Web Services Edge Conference Coverage on SYS-CON.TV
- Five Reasons Why Web 2.0 Matters
- SYS-CON.TV's "SOA Web Services" and "Enterprise Open Source" Programs To Air in December
- SOA World Conference & Expo SYS-CON.TV Power Panel Live From Times Square









There are a variety of applications that supp...




















