Scope

In this short article we will see how we can create Trading Partner EDI,AS2 agreements and batches in BizTalk using C# and  the built in functions of Microsoft.BizTalk.B2B.PartnerManagement. We will create a console application which can provide us a exe for calling through our deployment packages.

Overview

During one of our projects we came up with a problem where we had to create over 20 agreements consisting of AS2 and EDI for a partner. Now we all knew that this can be done through the BizTalk Administration console and we had given our build showing these as screenshots in our deployment document. But then our Production engineers came back saying that they have 12 servers and they cannot install 20 agreements within 1 hr of downtime. Now this forced us to put on our thinking caps. We all started to find options for doing this. We had all thought that this would be a easy task as previously using BizTalk server 2009 BiztalkExplorerOM party creation was very easy. But then BizTalk 2013 has Trading Partners and there was no direct way of creating these agreements.

Then after searching thru the internet we found this dll Microsoft.BizTalk.B2B.PartnerManagement.This is present in C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\Developer Tools\Microsoft.BizTalk.B2B.PartnerManagement.dll

Prerequisites

  • Microsoft BizTalk server 2013 ,R2 .
  • .NET 4 using Visual Studio 2013

Implementation

Creating a console application

We created a console application because that will give us an exe which we could call from Deployment solutions. For this we opened our friendly Visual Studio IDE and created new console application using the Visual Studio Template.

We then added reference to Microsoft.BizTalk.B2B.PartnerManagement. This is present in C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\Developer Tools. This assembly gives us the methods to create agreements programmatically.

Creating Party Agreement properties Xml File

We created a XML file which closely reflected our requirements of

  •                New BusinessProfile Creation for existing partner or new partner.
  •                New Partners creation.
  •                Addition of identities to existing partners and new partners.
  •                New X12 and AS2 agreements.
  •                Addition of new SchemaOverides and Envelope settings.
  •               Enabling of 997 Acknowledgment.
  •               Creation of new EDI batches.

The xml file structure was as follows:

        

We then used xsd.exe to convert our xml into a C# class which can be used to access our xml object in runtime.

Create of the TPAM Functionality Class      

We then created a class calling methods from this Microsoft.BizTalk.B2B.PartnerManagement dll to create of agreements. A little bit of reflection also came handy.Back to .NET roots is what I would say.

Now we were ready to use our exe passing our BizTalk management DB configuration string and BiztalkPartyXml and voila our agreements and Batches got created.

Conclusion

Our tool for creating BizTalk agreements is ready. I have put the code in GitHub so that it can be modified by others. Basically I have updated the tool to allow updates for an agreement. Currently it only handles new properties. Code currently checks if a concerned feature is present or not else it add the functionality. Also in future we will try creating a PowerShell script to use the already created functions.

Source Code 

You can find the source code used in this article here: Link

See Also

Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.