| Denzil Pinto さんのプロフィールTheBuzzフォトブログリスト | ヘルプ |
|
5月1日 Creating BizTalk Schemas using BizTalk Server 2004
Now to get started BizTalk Server 2004 uses XML format. So what this means is that BizTalk converts all messages into XML format before processing it. If you open the Visual Studio.Net and then click on File > New Project. To view images select Creating BizTalk schemas using BizTalk Server 2004 in the photo album and view the BizTalk project image.
· Select Empty BizTalk Server project and type in a name “BizTalk Test Project” and location. · Once the Solution has loaded right click on the project “BizTalk Test Project” and select Add > Add New Item. To view images select Creating BizTalk schemas using BizTalk Server 2004 in the photo album and view BizTalk Templates image.
Select Schema and type in the name “MailSchema.xsd” and select open. So now what you see is the BizTalk Editor. So what is this schema, well a schema contains the data structure definitions. In simple words let us say you want to exchange messages between applications (purchase order system and inventory system). Then you would have two schema definition files in your BizTalk project one containing the data structure definition of your order message and the next containing the data structure definition of your inventory message. BizTalk uses “xsd” (XML Schema definition language), to define the structure of all the messages that you want BizTalk to process. View the BizTalk Schema Editor
Each unique document type (purchase order and inventory) would require a separate schema. As a general suggestion it would be nice to maintain separate folders in your solution when you are designing your BizTalk solution. View Folder for Schemas image So to get back to our “MailSchema.xsd” let us take a look at the XML Schema
<xs:element name="SendMail"> <xs:complexType> <xs:sequence> <xs:element name="To" type="xs:string" /> <xs:element name="CC" type="xs:string" /> <xs:element name="Subject" type="xs:string" /> <xs:element name="EmailText" type="xs:string" /> <xs:element name="Priority" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element>
So if you take a good look at this example you will notice that this XML schema actually defines Elements and their datatypes. The elements are SendMail, To, CC, Subject, EmailText and Priority and the datatypes are all string.
Generally an XML Schema defines several things: · Elements, attributes and data types · Number of Occurrences, whether single or multiple in a single document. · Ordering of tags.
If you look at the XML schema you might wonder what <xs:complexType> is. So let us try and understand the difference between a simple type element and a complex type element.
To put it simply simple types cannot have children elements or attributes. Complex types on the other hand may have several children elements and attributes.
Simple element : <xs:element name=”EmailAddress” type=”string”/>
So by now you have figured it out that the schema for MailSchema.xsd is a complex type. Also in the XSD pasted above you might have noticed that “To, CC, Subject, EmailText, and Priority” are surrounded by <sequence>. This means that the child elements of “SendMail” must appear in the same order that they have been declared above. So “To” will come first, and then “CC” and so on.
So just one more thing before we plunge into creating our BizTalk Schemas. Let us discuss node types. When you insert nodes you are shown different node types. Take a look at the image Node Types
· Child Record: This type of node is a record node and can include simple types and can also include complex types. Take a look at the image Child Record
· Field Attribute: Represents items of information like numbers and strings. Take a look at the image Field Attribute
· Choice Group: This type of node contains other nodes; only one of which would appear in a message. For instance in the example below there are two address caAddress or usAddress one of them would be available in a message instance. Take a look at the image choice group
If you do require at least one address in a message instance then set the minOccurs to 1 and the maxOccurs to 1.
· Child Field Element: Represents items of information that are simple such as numbers and strings.Take a look at the image Child Field Element
· Sequence Group: This node type contains other nodes that must appear in the same order in an instance message as it appears within the sequence group.
Now let us start creating the schema. The example here uses XML file as an input into BizTalk.
Well let us take a real world scenario you are approached by your client and given an xml file that looks like the one below and you have to create a BizTalk Schema to represent this message.
<SendMail> <To>Test</To> <CC>Test1</CC> <Subject>Testing</Subject> <EmailText>EmailText_0</EmailText> <Priority>Priority_0</Priority> </SendMail>
So lets begin, · Open your visual studio environment and create a new solution file called “SendMailTest”. · On the project file right click and select Add > Add New Item. · From the templates select Schema and type in the name as “MailSchema.xsd”. You will the BizTalk Editor open in front of you. · Right click on Schema and select Insert Schema Node > Child Record · Enter the Name as SendMail. You can also rename the node from the properties window. Scroll down to Node Name. · Right click on SendMail node and select Insert Schema Node > Child Field Element. Enter the Name “To”. Do the same steps for “CC”,”Subject”,”EmailText”,”Priority”. You should have a schema that looks like the figure below. Take a look at the mailschema.xsd image.
So now you have created your first schema. Now let us try and validate it against the xml file. So to do that copy the below code into an xml file and name it “SendMailTest.xml” and save it in a temp folder.
<SendMail> <To>Test</To> <CC>Test1</CC> <Subject>Testing</Subject> <EmailText>EmailText_0</EmailText> <Priority>Priority_0</Priority> </SendMail>
Now right click on MailSchema.xsd in your solutions explorer and select properties. Select Input Instance Filename and click on the ellipsis button, browse to your temp folder and select “SendMailTest.xml”. Make sure the Generate Instance Output Type is XML and the Validate Instance Input Type is also XML. The validate instance input type is in this case is XML because you’re input file is in XML format.
Now in order to validate, right click on “MailSchema.xsd” in your solution explorer and select “Validate Instance”. In order to see the errors you need to have the Task List and the Output window open. Select View > Other Windows > Task List and then Output Windows.
Once open click on the Output tab you will see the error message like this “Could not find schema information for the element SendMail”. So now we need to fix this issue. So let us first start by investigating the Target Namespace of your schema. To do that, select the Schema and right click and select properties. Take a look at the open properties window image
If you scroll down in the properties window, you will find Target Namespace. Copy the Target Namespace completely and then go to your “SendMailTest.xml” file that you saved in the temp folder open it and at the SendMail node add “xmlns=” and then paste the target namespace. So now your SendMailTest.xml should look like the following
<SendMail xmlns="http://BizTalk_Server_Project5.MailSchema"> <To>Test</To> <CC>Test1</CC> <Subject>Testing</Subject> <EmailText>EmailText_0</EmailText> <Priority>Priority_0</Priority> </SendMail>
Now save this file and again right click on MailSchema.xsd in your Solution Explorer and select Validate Instance. Again you will see errors, if you open your output window then you will see the error message as “The element http://<your projectname>.MailSchema:SendMail has invalid child element ‘http://<your project name>.MailSchema:To. Expected ‘To’.” Well now to solve this problem let us try and figure out what the error message is trying to tell us.
Well what the error message says is that your input file has now qualified all your child elements to the namespace. That means the child elements To, CC are now all qualified to the namespace that we added at the SendMail level ‘xmlns=”http//<your projectname>.MailSchema”’. So when it tries to validate your input file with the BizTalk schema it finds that To,CC etc in BizTalk is not qualified.
In order to qualify your BizTalk Schema, Click on Schema in your BizTalk Editor and select properties again like you did in Figure 9. In properties window scroll down to “ElementFormDefault” in the Advanced Tab and choose from the drop down list “Qualified”. Save your changes and again try and validate your schema and it should now validate without any issues. To validate again select “MailSchema.xsd” in your Solutions Explorer and right click and select “Validate Instance”.
Well you have now created your first BizTalk Schema and have validated it as well.
When developing you message schemas you notice a certain portion repeated over and over. For instance address might be repeated in various message structures in your solution. Let us say we have two schemas to create, customer.xsd and the other supplier.xsd both of which have address as a repeating structure. So let us start by creating the two schemas. View Customer.xsd and then Supplier.xsd
In the common folder create a schema called Address.xsd. View Address.xsd image.
Now we need to add the address.xsd to the customer and supplier schemas. BizTalk offers three ways to import existing schema they are import, include and redefine. We are going to use the import mechanism. So before we begin, we should spend some time on namespaces. If you select Address.xsd in the properties window you have namespace, it would be a good practice to give a meaningful namespace like “BizTalk_Sample_Project.Common.Address” <projectName><folderName><schemaName> you can follow a pattern that you are comfortable with. Do the same for customer and supplier for this example I have given them the following namespaces, “BizTalk_Sample_Project.Schemas.Customer”,”BizTalk_Sample_Project.Schemas.Supplier”. View the namespace image. Now in order to import address in the customer schema select customer.xsd and then select Schema node, in the properties window click on the Imports ellipsis. View Showing the Properties window for the Schema node The Imports Dialog Window will open make sure that XSD import is selected from the list of Import New schema as and then click on Add . View Imports Dialog Window image.
From the BizTalk Type picker expand Schemas and select the namespace for the address schema (“BizTalk_Sample_Project.Common.Address”). Now you have imported the address schema in your customer schema. Now add a new record node and name it Address. View Example:Child Record image
Select Address in the properties window select Data Structure Type and choose “ns0:Address” . View Data Structure Type image.
Address is now a part of your customer.xsd. So you have successfully imported address into your customer schema. トラックバックこの記事のトラックバックの URL は次のとおりです。 http://denzilpinto.spaces.live.com/blog/cns!A2256C53CD2EC18E!109.trak この記事を参照しているブログ
|
|
|