1. Problem
You want to create an external .NET application that can be used by administrators to create and modify ports on BizTalk Server.
2. Solution
You can create and modify a
variety of components programmatically using the BizTalk Explorer object
model. This solution will walk you through creating a basic C# Windows
Form application that calls the object model.
NOTE
The Microsoft.BizTalk.ExplorerOM.dll
assembly can only be used from 32-bit systems. You can reference it in
Visual Studio on a 64-bit system, but it will not work once the code is
compiled.
Here are the steps to follow:
In Visual Studio, create a new project of type Windows Forms Application (as shown in Figure 1).
Add
a reference to the assembly called Microsoft.BizTalk.ExplorerOM.dll.
This assembly is located in $\Program Files\Microsoft BizTalk Server
2010\Developer Tools.
Create a new button on the form. The code will be implemented in the code behind this button for this demonstration solution.
Double-click the button to access the code behind, and enter the information listed in Listing 1.
Example 1. Creating Ports in C#
private void button1_Click(object sender, EventArgs e) { // instantiate new instance of Explorer OM BtsCatalogExplorer btsExp = new BtsCatalogExplorer();
// connection string to the BizTalk management database where the ports will be created btsExp.ConnectionString = "Server='SR';Database='BizTalkMgmtDb';Integrated Security=true";
// new BizTalk application Microsoft.BizTalk.ExplorerOM.Application app = btsExp.AddNewApplication(); app.Name = "AppCreatedInCode"; btsExp.SaveChanges();
// new BizTalk File Send Port SendPort send = app.AddNewSendPort(false, false); send.Name = "SendCreatedInCode";
send.PrimaryTransport.TransportType = btsExp.ProtocolTypes["File"]; send.PrimaryTransport.Address = "C:\\Drops"; send.SendPipeline = btsExp.Pipelines["Microsoft.BizTalk.DefaultPipelines.PassThruTransmit"];
// new BizTalk WCF-BasicHttp Receive Port ReceivePort receive = app.AddNewReceivePort(false); receive.Name = "ReceiveCreatedInCode"; receive.PrimaryReceiveLocation.TransportType = btsExp.ProtocolTypes["WCF-BasicHttp"]; receive.PrimaryReceiveLocation.Address = "http://demo/demofolder"; receive.PrimaryReceiveLocation.ReceivePipeline = btsExp.Pipelines["Microsoft.BizTalk.DefaultPipelines.XmlReceive"];
// save all of the changes btsExp.SaveChanges(); }
|
3. How It Works
You can access a wide
variety of functionality through the BizTalk ExplorerOM assembly,
including ports, applications, orchestrations, bindings, and party
information. When using the BizTalk Administration Console is not the
ideal option, the Explorer Object Model opens up a number of
programmatic options.