| Profil de Denzil PintoTheBuzzPhotosBlogListes | Aide |
|
16 mai Call an External Assembly from a mapBizTalk Map gives you the ability to call an external assembly by using a Scrpting functoid. Sometimes you need some additional functionality and the ability to call an external assembly is great.
We are going to get started by creating a new BizTalk project file in Visual studio. Then we are going to create two new schemas
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 OrderID and press Enter. Again Right click on order and select Insert Schema node and select Child Field Element. Enter the name Description and press Enter.
4. Now we are going to add a new Child Record. Again Right click on Order and select Insert Schema Node and select Child Record, enter the name Unit and press Enter.
5. Follow the 3 step and create new Child Field Elements called UnitID, Description,TotalUnits,Price.
6. Now click on TotalUnits and right click and select properties, goto the DataType and select xs:int. Follow the same steps for the Price and select xs:int for the datatype.
7. 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 OrderID. Follow the same step and create another Child Field Element called Description.
4. Now add a new Child Record called Unit. To do that right click on Purchase node and select Insert Schema Node and select Child Record, enter the name Unit and press Enter.
5. Follow the 3 step and create new child field elements called Description, Units, Price and Total.
6. Now click on Total and right click and select properties, goto the DataType and select xs:int.
7. We have now created our second schema. The Total in this schema will be (Price X Units).
OrderItemsToPurchasemap
------------------------------------
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 click on OrderID in the Source Schema and then drag it across the grid to the destination field " OrderID" in the destination schema. Do the same for Description.
4. Click on Description the child field element from Unit and drag it across the grid to the destination field "Description" in the destination schema.
5. Click on TotalUnits and drag it across the grid to the destination field Units in the destination schema. Click on Price and drag it across the grid to the destination field Price in the destination schema.
Now we are going to add a functoid.
-----------------------------------------------
1. If you dont have the Toolbox open Click on View > ToolBox.
2. Click on Advanced Functoids and click on scripting, drag and drop it on the grid portion of the mapper.
3. Click on TotalUnits in your Source Schema (OrderItems), and drag and drop it on the Scripting Functoid.
4. Click on Price in your Source Schema(OrderItems), and drag and drop it on the Scripting Functoid.
Class Library
------------------
1. Well lets now create a new Class Library. Go to your Solution Explorer, click on your Solution, right click and select New Project.
2. From the Project Types select Visual C# Projects and from the templates select Class Library. Enter a new Name and click OK.
3. Rename Class1 to TestClass.cs. To do that right click on Class1 and select Rename, enter the name TestClass.cs.
4. Open the new class and paste the code below
using System;
namespace BizTalkLink
{ public class TestClass { public TestClass() { } public int calculateTotal(int unit, int price)
{ int total; total=(unit * price);
return total;
}
} } 5. Now lets build your solution. Save all your work. Click on Build > Build Solution.
Strong Name Key
------------------------
1. Now we need to strong key your class library. Open the command prompt, Click on All Programs > Microsoft Visual Studio .Net 2003 > Visual Studio .Net Tools > Visual Studio .Net 2003 Command Prompt.
2. Navigate to where your have created your new class library project.
3. To derive a strong key type the following command: sn -k test.snk.
4. Once you have done that then go to you class library AssemblyInfo.cs.
5. We need to edit the assemblykeyfile : [assembly: AssemblyKeyFile("c:\\solutions\\biztalksolution\\externalassemblytest\\test.snk")]. So now it will contain the location to your strong key file you just generated. Here we have specified the physical path, but you can specify relative path and that will be covered in another example.
6. Click on Build Solution again and make sure there are no errors.
gacutil
-----------
1. Now we need gac your new dll.
2. Go to your command prompt again and navigate to the bin/debug folder. for instance in my case that would be c:\solutions\biztalksolution\externalassembly\bin\debug.
3. There you should find a dll which in my case is externalassembly.dll.
4. Now lets gac it. Type the following command : gacutil /if externalassembly.dll.
5. Open your windows explorer and goto your windows folder and then click on assembly. You should see your new dll there for instance in my case is "externalassembly".
You need to now add a reference to your biztalk project for you to be able to access your new dll.
1. Now lets add a new reference to our BizTalk project. In your BizTalk project right click on references > add reference.
2. Click on the Projects Tab and select your project click on select and click on OK.
3. Now you have added a new reference to your biztalk project
1. Now lets go back to our Scripting Functoid in our OrderItemsToPurchasemap.btm.
2. Right Click on the Scripting functoid and select Properties.
3. Click on Input Parameters and select the ellipsis, you will notice that TotalUnits and Price are the input parameters
4. Click OK to close and click on Script and click on the ellipsis. From the Script Type drop down select External Assembly
5. From the Script Assembly select your class library project file that you just created.
6. From the script class select the class.
7. From the Script method select the method.
8. Click on OK.
9. Click on Total in your destination schema and drag and drop it on the scripting functoid.
10. Save your work.
1. Well we havent finished as yet, we still need to verify that the version number and the public key token of our external assembly is the right one
2. so now right click on OrderItemsToPurchasemap.btm and select open with > HTML/XML Editor and click open. Click ok if prompted that the document is already open.
3. Now you can see the XML if your document is not formatted correctly. Select View > Toolbars > HTML Editor.
4. If you move your mouse over the html editor you will find an icon that formats your whole document. Click on that. It should be the first icon on your html editor toolbar.
1. Now scroll down to <ScripterCode>
2. Now if you scroll to the right you will see the Version and the PublicKeyToken.
3. If you havent already lets again open our explorer and click on the windows folder and then the assembly folder. Select externalassembly from the right pane and rightclick on it and choose properties.
4. Copy the version and the publickeytoken and replace it in your orderItemsToPurchasemap.btm.
5. Save your work.
6. Now right click on your OrderItemsToPurchaseMap.btm in your solutions explorer and click on Test Map.
Commentaires (4)Pour ajouter un commentaire, connectez-vous avec votre identifiant Windows Live ID (si vous utilisez Messenger ou Xbox LIVE, vous avez un identifiant Windows Live ID). Connectez-vous Vous n'avez pas d'identifiant Windows Live ID ? Inscrivez-vous
RétroliensL'URL de rétrolien de ce billet est : http://denzilpinto.spaces.live.com/blog/cns!A2256C53CD2EC18E!193.trak Blogs Web qui font référence à ce billet
|
|
|