You are on page 1of 12

Microsoft Virtual Labs

Working with Schemas


Working with Schemas

Table of Contents
Working with Schemas................................................................................................................. 1
Exercise 1 Creating a New BizTalk Project ..................................................................................................................2
Exercise 2 Creating an XML Schema Using BizTalk Editor ........................................................................................3
Exercise 3 Promoting Schema Properties ......................................................................................................................5
Exercise 4 Creating a Flat File Schema using The Flat File Schema Wizard................................................................6
Exercise 5 Validating Schemas and Generating Instance Messages .............................................................................7
Exercise 6 Assigning a Strong Name to the Assemblies ...............................................................................................9
Exercise 7 Building the Schema Project......................................................................................................................10
Article I.
Working with Schemas

Working with Schemas


After completing this lab, you will be better able to:
Objectives ƒ Create a new BizTalk project.
ƒ Create an XML schema by using the BizTalk Editor.
ƒ Promote a schema property.
ƒ Create a flat file schema by using the BizTalk Editor.
ƒ Validate a schema and generate a sample instance message.
ƒ Create a strong name and assign it to an assembly.
ƒ Build a schema project.
Northwind Traders has chosen to create a custom schema to meet their business
Scenario requirements for submitting orders to a supplier. In this lab you will create a
BizTalk project for the schema, and then define a customer order schema to
define the structure of messages (documents) to be exchanged within the
solution.
You will also promote several of the schema properties so that the property
values can be referenced for content-based routing purposes in the BizTalk
orchestration that you will create in later labs.
After you have created the schemas and promoted the schema properties, you
will use the BizTalk Editor to generate a sample instance message and validate
the schemas to check for any inconsistencies.

Estimated Time to 45 Minutes


Complete This Lab

Computer used in this The password for the Administrator account on this computer is: pass@word1
Lab

Page 1 of 10
Working with Schemas

Exercise 1
Creating a New BizTalk Project

Scenario
In this exercise, you will build a new solution for this project by using the Microsoft Visual Studio® .NET 2005
environment. First you will create a new blank solution, and then you will add a new project to the solution. This
project will contain the schemas that you will create in the following exercises.

Tasks Detailed Steps


1. Configure the a. On the desktop double-click the SetupLab.bat shortcut.
starting lab b. In the Lab Setup Menu, type 2.
environment.
2. Create a blank c. Click Start | All Programs | Microsoft Visual Studio 2005 | Microsoft Visual
solution. Studio 2005.
A solution might include only one The Visual Studio 2005 splash screen appears and then Visual Studio starts.
BizTalk project if the solution is
relatively simple.
d. In Visual Studio, click File | New | Project.
A solution might include many e. In the New Project dialog box, expand Other Project Types, click Visual Studio
BizTalk projects if the solution Solutions, and then click the Blank Solution template.
consists of numerous projects
that are developed f. In the Name box, type NWBusinessSolution as the solution name.
independently and then must be g. In the Location box, type C:\Labs\Work\Lab02.
integrated later.
h. Click OK to open the new solution.
A new solution appears in Solution Explorer and the solution files are created in
C:\Labs\Work\Lab02\NWBusinessSolution.
3. Add a new BizTalk a. In the Solution Explorer, right-click Solution 'NWBusinessSolution', point to
project to the Add | New Project.
solution. b. In the Add New Project dialog box, in the Project Types pane, click BizTalk
Selecting the BizTalk project Projects.
template exposes the BizTalk
tools, such as BizTalk Mapper, c. In the Templates pane, select Empty BizTalk Server Project.
within the Visual Studio .NET d. In the Name box, type NWMessaging and click OK.
development environment, and
A new project is added to Solution Explorer, and the starting project files are created
invokes a BizTalk-specific
compiler.
in C:\Labs\Work\Lab02\NWBusinesSolution\NWMessaging.
e. In the Solution Explorer, under NWMessaging, expand References to view the
default references that get added to a new project.

Page 2 of 10
Working with Schemas

Exercise 2
Creating an XML Schema Using BizTalk Editor

Scenario
In this exercise, you will create a schema to define the structure of the shipping address record. You will also open
an existing schema and use the import function to insert schema nodes within the existing schema.

Tasks Detailed Steps


1. Create the shipping a. In the Solution Explorer, right-click the NWMessaging project and point to Add
address schema. | New Item.
Selecting the Schema template b. In the Add New Item dialog box, in the Categories pane, select Schema Files and
causes BizTalk Editor to start. in the Templates pane, select Schema.
c. In the Name box, type ShippingAddress.xsd to name the schema.
d. Click Add to open the blank schema in BizTalk Editor.
The schema tree (left pane) and XSD view (right pane) appear in BizTalk Editor. Also,
the new schema (ShippingAddress.xsd) is added to Solution Explorer.
2. Create the schema a. In the Schema Tree, right-click the Root node, and then click Rename.
record. b. Type ShippingAddress as the new name, and then press ENTER.
The Root node should always be c. Right-click the ShippingAddress node, point to Insert Schema Node and click
renamed using a meaningful
name that represents the type of Child Field Element to add the following fields (repeat this step for each field
document described by the element):
schema. When possible, use a ƒ City
root node name unique ƒ Country
throughout the enterprise.
ƒ Street
ƒ Email
You can right-click an empty
area of the Toolbar and select
ƒ Fax
BizTalk Editor to display a ƒ State
floating toolbar of BizTalk Editor ƒ Zip
options. ƒ Phone
d. On the File menu click Save All.
3. Open an existing a. In the Solution Explorer, right-click the NWMessaging project, point to Add |
schema and import a Existing Item.
new child record. b. Browse to C:\Labs\Work\Lab02, and double-click the CustomerOrder.xsd
This allows you open an existing schema to add it to the project.
schema and use the import
function to insert schema nodes
The schema is added to Solution Explorer.
within an existing schema. c. In the Solution Explorer, double-click CustomerOrder.xsd to open it in BizTalk
Editor.
You can show properties in
alphabetical order by clicking the d. If the Properties window is not visible, then in the BizTalk Editor, right-click the
Alphabetic button at the top of <Schema> node of CustomerOrder.xsd, and then select Properties.
the Properties window. e. In the Properties window, click the Imports property and click the Ellipsis (…)
button.
f. In the Imports dialog box, verify that XSD Import is selected from the drop-
down box and click Add.
g. In the BizTalk Type Picker dialog box, expand NWMessaging, expand Schemas,
click NwMessaging.ShippingAddress and click OK.
h. Click OK to close the Imports dialog box.

Page 3 of 10
Working with Schemas
Tasks Detailed Steps
i. Right-click the CustomerOrder root node, click Insert Schema Node and click
Child Record.
j. Click the child record Record, then in the Properties window, select the Data
Structure Type property, and from the list, select ns1:ShippingAddress
(Reference).
The ShippingAddress record is added to the schema.
k. On the File menu click Save All.

Page 4 of 10
Working with Schemas

Exercise 3
Promoting Schema Properties

Scenario
In this exercise, you will promote schema properties so that the property values can be referenced by BizTalk
messaging and orchestration. Promotion is a mechanism that you must use when you want to reference a specific
value within a message instance and then use the value to make message routing decisions. Additionally, the
promoted property will be visible by IntelliSense in Expression Editor when code is required in an orchestration.

Tasks Detailed Steps


1. Promote property a. In BizTalk Editor, in the Schema Tree, right-click the <Schema> node and click
fields. Expand Schema Node to show the entire schema.
The property fields are promoted b. Under the Customer Order node, right-click CustomerPONumber, point to
so that their values can be Promote and click Quick Promotion.
referenced for content-based
routing purposes and c. Click OK to add the property schema to the project.
orchestration. The icon has changed to indicate that the field has been promoted. Also, a new schema
(PropertySchema.xsd) is added to the Solution Explorer.
d. Right-click TotalOrderAmount, point to Promote and click Quick Promotion.
2. Promote a. Right-click the <Schema> node, point to Promote and click Show Promotions.
distinguished fields. b. Select the following fields from the Schema (left) pane and add them as
The distinguished fields are distinguished fields:
promoted so that their values
ƒ Status
can be referenced in an
orchestration that you will create
ƒ Comments
in later labs. c. Click OK.
d. On the File menu click Save All.

Page 5 of 10
Working with Schemas

Exercise 4
Creating a Flat File Schema using The Flat File Schema
Wizard

Scenario
In this exercise, you will create a flat file schema to define the structure of a customer contact record.

Tasks Detailed Steps


1. Create the customer a. In the Solution Explorer, right-click the NWMessaging project, point to Add |
contact schema. New Item.
This creates the XSD schema b. In the Add New Item dialog box, in the Templates pane, select Flat File Schema
that describes the XML structure Wizard.
that flat files will be converted to.
c. In the Name box, type CustomerOrderFlatFile.xsd and click Add.
d. In the BizTalk Flat File Schema Wizard, click Next.
e. On the Flat File Schema Information page, in the Instance file box, browse to or
type C:\Labs\Work\Lab02\CustomerOrder.txt.
f. In the Record name box, type Customers and click Next.
g. On the Select Document Data page, select only the first line of data and click
Next.
h. On the Select Record Format page, verify that By delimiter symbol is checked
and click Next.
i. On the Delimited Record page, set the Child Delimiter to , (Comma) and click
Next.
j. On the Child Elements page, change the Element Names to:
ƒ FirstName
ƒ MiddleName
ƒ LastName
ƒ ContactNo
k. Click Next and click Finish to create the schema.

Page 6 of 10
Working with Schemas

Exercise 5
Validating Schemas and Generating Instance Messages

Scenario
In this exercise, you will use the Validate Schema command to determine whether the schemas contain any internal
inconsistencies, or have other issues that might prevent them from being used effectively for processing instance
messages. You will also generate a sample instance message for each of the schemas.

Tasks Detailed Steps


2. Validate the schema a. In the Solution Explorer, right-click CustomerOrder.xsd and click Validate
file. Schema.
Validating the schema ensures The results of the schema validation are displayed in the output window. The schema
that an XML document can be validation tool is helpful when using schemas you’ve received from other parties or
created that would be well- trading partners, that may not have been generated using BizTalk Server. BizTalk
formed and valid against this schemas will always validate.
particular schema.

3. Generate a sample a. Right-click CustomerOrder.xsd and click Properties.


instance message for b. In the CustomerOrder.xsd Property Pages dialog box,
the schemas. in the Output Instance Filename box, type
Generating a sample instance C:\Labs\Work\Lab02\GeneratedCustomerOrder.xml and click OK.
provides a visual test as well as
a document to pass through the c. In Solution Explorer, right-click CustomerOrder.xsd and click Generate
process for testing. Instance.
A sample instance message is saved in C:\Labs\Work\Lab02, and a link to the XML
instance is shown in the Output window.
d. Click the link while pressing CTRL to view the resulting XML file.
4. Validate the sample a. In the Solution Explorer, right-click CustomerOrder.xsd and click Properties.
instance message. b. In the CustomerOrder.xsd Property Pages dialog box,
The CustomerOrder.xml XML file in the Input Instance Filename box, type
is provided so that you can C:\Labs\Work\Lab02\CustomerOrder.xml and click OK.
check for errors in the schema
you just created. c. Right-click the CustomerOrder.xsd schema file and click Validate Instance.
The results of the instance validation are displayed in the output window. This step
validates the schema against an actual XML file.
5. Validate the flat file a. In the Solution Explorer, right-click CustomerOrderFlatFile.xsd and click
sample instance. Properties.
The CustomerOrder.txt flat file is b. In the CustomerOrderFlatFile.xsd Property Pages dialog box, verify the
provided so that you can check following properties:
for errors in the schema you just
created Property Value
Input Instance Filename C:\Labs\Work\Lab02\CustomerOrder.txt
Validate Instance Input Type Native
c. Click OK to close the CustomerOrderFlatFile.xsd Property Pages dialog box.
d. Right-click the CustomerOrderFlatFile.xsd schema file and click Validate
Instance.
The results of the instance validation are displayed in the output window. This step
validates the schema against an actual flat file.
e. In the Output window, while holding CTRL, click the top link (ends with
output.xml).

Page 7 of 10
Working with Schemas
Tasks Detailed Steps
The window that opens displays the xml that was generated. Notice that the entire
second record is included in the ContactNo element. That is incorrect.
f. Close the preview pane.

Page 8 of 10
Working with Schemas

Exercise 6
Assigning a Strong Name to the Assemblies

Scenario
In this exercise, you will create and assign a strong name for the BizTalk assemblies that you are about to build. A
strongly-named assembly provides several security benefits. A strong name guarantees the uniqueness of the
assembly by assigning a digital signature and a unique key pair. This also protects the lineage of the assembly by
ensuring that no one else can generate a subsequent version of that assembly. And finally, a strong name provides a
strong integrity check to guarantee that the contents of the assembly have not been changed since it was built.

Tasks Detailed Steps


6. Create a strong name a. Click Start | Programs | Microsoft Visual Studio 2005 | Visual Studio Tools |
assembly key file. Visual Studio 2005 Command Prompt.
This creates a strong name b. At the command prompt, type cd \Labs\Common, and then press ENTER.
public/private key pair, which is
saved to an assembly key file. c. Type sn –k Key2.snk, and then press ENTER.
A message appears, indicating that the key pair has been written to the key file
(Key2.snk).
d. Close the Command Prompt window.
7. Assign a strong name a. In the Solution Explorer, right-click the NWMessaging project and click
to the assembly. Properties.
This assigns the key file to the b. In the left pane of the NWMessaging Property Pages dialog box, click
assembly. You must do this for Assembly.
each of the projects in this
solution. c. In the right pane, scroll down to the Strong name section, click the field to the
right of Assembly Key File and click the Ellipsis (…) button.
d. In the Assembly Key File dialog box, browse to C:\Labs\Common\Key.snk (for
lab consistency you are using an already generated keyfile) and click Open.
e. Click OK to save changes.
f. On the File menu click Save All.

Page 9 of 10
Working with Schemas

Exercise 7
Building the Schema Project

Scenario
In this exercise, you will build the project to generate an assembly that contains the resources (the schemas) that you
have just created. This also ensures that that there are no compile-time errors in the work you have completed so far.

Tasks Detailed Steps


1. Build the project. a. In the Solution Explorer, right-click NWMessaging and click Build.
The assembly is compiled into a The results of the compiled schema project are displayed in the output window.
DLL file and saved in the
\\bin\Development folder within
b. Close Visual Studio.
the project folder.

Page 10 of 10

You might also like