| Profil von Denzil PintoTheBuzzFotosBlogListen | Hilfe |
|
01 Juni Data access block of enterprise library and BizTalk Map implementationWell inorder to get started you will need to generate strong key for the enterprise library so that we can GAC it. So kindly follow the previous blog entry . Link .
Now the next step would be to GAC
1. Microsoft.Practices.EnterpriseLibrary.Common
2. Microsoft.Practices.EnterpriseLibrary.Configuration
3. Microsoft.Practices.EnterpriseLibrary.Data
To GAC these assemblies navigate to Program Files\Microsoft Enterprise Library June 2005\bin and type in for instance gacutil /if Microsoft.Practices.EnterpriseLibrary.Common and do the same for 2 and 3. Another simpler way would be navigate to your Windows/Assembly folder and dragging and dropping the above dlls there.
After that is done then we need to create a new biztalk solution file and two new schema files : OrderItems and Purchase
OrderItems
-------------
1. Right click on your project file and click on Add > Add New Item . Select Schema from the Templates provided and enter the name OrderItems.xsd and click on Open.
2. In the Schema Editor Right click on the Root Node and select Rename from the list and enter the name Order and press Enter.
3. Right Click on Order and select Insert Schema Node and select Child Field Element. Enter the name UnitID and press Enter.
4. Right click on UnitID and select Properties, in the properties window scroll down to the DataType and select xs:int.
5. We have now created our first schema
Now lets create our second schema called Purchase.xsd
Purchase
------------
1. Right Click on your project file and click on Add > Add New Item. Select Schema from the templates provided and enter the name Purchase.xsd and click on Open.
2. In the Schema Editor Right click on the Root Node and select Rename from the list and enter the name Purchase and press Enter.
3. Right Click on Purchase and select Insert Schema Node and select Child Field Element. Enter the name Description.
4. We have now created our second schema.
Map
-----
1. Now lets create a new Map call it OrderItemsToPurchasemap.btm. For that you need to right click on the project file and select Add > Add New Items and from the templates select map, enter the name "OrderItemsToPurchasemap.btm" and select open.
2. In the Mapper tool, click on open source schema and drilldown Schema and select Order Items and then click on Open Destination Schema and drilldown Schema and select Purchase.
3. Now we are going to add a functoid.
4. From the Toolbox select Advanced Functoids and click on Scripting functoid, drag and drop it to the grid. Now click on UnitID drag and drop it to the scripting functoid. Now lets move away from our biztalk project and add a new class library to our solution file.
Class Library
----------------
Now let us create our new Class Library Project. Click on your solution file select Add > New Project. From the templates select Class Library and enter a name and click on OK.
Right click on Class1.cs and rename it. Now right click on references > Add Reference. Click on Browse and naviage to Program Files\Microsoft Enterprise Library June 2005\bin. Now select one at the time
1. Microsoft.Practices.EnterpriseLibrary.Common
2. Microsoft.Practices.EnterpriseLibrary.Configuration
3. Microsoft.Practices.EnterpriseLibrary.Data
Click on Open and then click on OK. You will see the new references added to your project file.
Now add the following code to your .cs file
using System;
using System.Data; using System.Text; using System.Reflection; using System.Globalization; using Microsoft.Practices.EnterpriseLibrary.Data; namespace BizTalkEnterpriseLibraryTest { public class TestClass
{ public TestClass() { } public string GetData(int param1)
{ string test; Database database = DatabaseFactory.CreateDatabase();
DBCommandWrapper storedProcQuery = database.GetStoredProcCommandWrapper("TestData"); storedProcQuery.AddInParameter("@param1",DbType.Int32,param1); test=(string) database.ExecuteScalar(storedProcQuery);
return test; } } } In this example I am trying to implement the Data Access application block. The first line Database database = DatabaseFactory.CreateDatabase() : creates a database object. I have created a stored procedure called TestData that requires you to send the UnitID and once a match is found it will send the Description. Once we have added in the code, compile and make sure there are no errors.
Now lets take a moment and take a look at the SQL Table and the stored procedure.
SQL Table
--------------
1. Lets add a new table to our Northwind database. The table should be called TestProduct.
2. There should be two fields
UnitID int
Description varchar 50
3. Add some data to your new table.
UnitID Description
1 Product1
2 Product2
3 Product3
StoredProcedure
--------------------
CREATE PROCEDURE TestData
@param1 int as Configuration Files
-------------------------
Now that we have that in place lets go create our configuration files. To do that you will have to Click on Start and All Programs > Microsoft patterns & practices > Enterprise Library - June 2005 > Enterprise Library Configuration.
Then click on File > New Application. Right Click on Application1 > New > Data Access Application Block
You will need to configure database, Integrated Security, server as per your settings. For me since I created a table in the northwind database. These are the values that I entered
Database : Northwind
Integrated Security : SSPI
server : local
You can click on database and on the right hand side populate the value field with the correct values. Do the same for Integrated Security and server.
Click on XML File Storage Provider and then click on FileName on the property grid on the right and then click on the ellipsis. Navigate to the Bin folder of your class library that you just created. For instance if your new Class library is called BizTalkEnterpriseTest. Navigate to BizTalkEnterpriseTest/bin/debug.
Now click on Application1 and click on ConfigurationFile and click on the ellipsis. Again Navigate to your BizTalkEnterpriseTest folder and enter the name as App.config and click on Save. So by doing this we have created our dataconfiguration.config and app.config.
Since we need to access the data access application block from a biztalk map we will need to do some more modifications to begin with we will need to updated the machine.config file with our app.config information.
<section name="enterpriselibrary.configurationSettings" type="System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<enterpriselibrary.configurationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" applicationName="Application1" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">
<configurationSections> <configurationSection xsi:type="ReadOnlyConfigurationSectionData" name="dataConfiguration" encrypt="false"> <storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="C:\BizTalkEnterpriseLibrary\bin\debug\dataConfiguration.config" /> <dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer"> <includeTypes /> </dataTransformer> </configurationSection> </configurationSections> <keyAlgorithmStorageProvider xsi:nil="true" /> <includeTypes /> </enterpriselibrary.configurationSettings>
Extra
-------
I had earlier created a post build event on my Class library project, I do not think we need it at this point because we have added our configuration information to the machine.config but I am just adding it here anyways : Inorder to create a post build event you will need to right click on you class library file and select properties : Common Properties ->Build Events and enter the following code in the post build event copy "$(ProjectDir)app.config" "$(TargetDir)". What this does is it copies the app.config file from your project directory to the bin/debug directory. You class library can pick up the confiuration from the app.config file if it is available in the bin/debug folder.
Compile your class library project file which in my case is BizTalkEnterpriseLibrary and make sure there are no errors.
Now we also need to edit your dataconfiguration.config file. What we need to do is add the public token keys which is null at the moment.
To do that navigate to you biztalkenterpriselibrary/bin/debug and open another windows explorer, navigate to c:\windows\assembly. Right click on Microsoft.Practices.EnterpriseLibrary.Data and select properties. Copy the public token key and add it in your dataconfiguration.config file in the two places where it shows public token key = null. If you donot do this when you test your map you it will generate errors because it cannot match the assembly correctly. If you look at the extract below you will notice that I have added the publickeytoken which was null in the generated file.
My dataconfiguration.config file looks like
-----------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration> <xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral, PublicKeyToken=05efaff33af8bc6f"> <enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="Database Instance" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data"> <databaseTypes> <databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral, PublicKeyToken=05efaff33af8bc6f" /> </databaseTypes> <instances> <instance name="Database Instance" type="Sql Server" connectionString="Sql Connection String" /> </instances> <connectionStrings> <connectionString name="Sql Connection String"> <parameters> <parameter name="database" value="NorthWind" isSensitive="false" /> <parameter name="Integrated Security" value="SSPI" isSensitive="false" /> <parameter name="server" value="LOCAL" isSensitive="false" /> </parameters> </connectionString> </connectionStrings> </enterpriseLibrary.databaseSettings> </xmlSerializerSection> </dataConfiguration> So now that all is done you need to GAC the class library that you created. Inorder to do that compile it first and make sure there are no errors and then navigate to( for instance BizTalkEnterpriseLibrary/Bin/debug )and using the Visual studio.net Command prompt enter gacutil /if BizTalkEnterpriseLibrary.dll. If you navigate to c:\windows\assembly folder you should find all the assemblies that you just GAC.
The only step left is to complete the map. Go back to you biztalk solution and click on OrderItemsToPurchasemap.btm and click on the Scripting Functoid.
In the properties window click on Script. Select the ellipsis and then in the configure Functoid Script select External Assembly. In the script assembly select the assembly and in the script class select class and in the script method select the method that you need to call. Click on OK. Click on Description drag and drop it to the Scripting functoid and test your map.
Test Map
-----------
Test Map -----------
Now lets test our map. Inorder to test we need a xml file for input
XML File ------------ <Order xmlns="http://BizTalk_Mapper.OrderItems">
Now save the above xml to your hard drive. In your solution explorer right click on the map and click on properties. Update the values
Validate TestMap Input - True
Validate TestMap Output - True
TestMap Input Instance - c:\test.xml (XML file that you just created).
TestMap Input - XML
TestMap Output - XML.
Click on OK.
Now right click on your map in your solution explorer and click on Test Map. In the output window ( View > Other Windows > Output) you will see a file where you output is stored. Open it and you will notice that description for Unit is "Product 2" Kommentare (4)Melden Sie sich zum Hinzufügen eines Kommentars mit Ihrer Windows Live ID an (wenn Sie Hotmail, Messenger oder Xbox LIVE verwenden, besitzen Sie eine Windows Live ID). Anmelden Sie haben noch keine Windows Live ID? Registrieren
TrackbacksDie Trackback-URL für diesen Eintrag ist: http://denzilpinto.spaces.live.com/blog/cns!A2256C53CD2EC18E!210.trak Weblogs, die sich auf diesen Eintrag beziehen
|
|
|