Activate a Biztalk Receive Location using Code

With this code yo can (re)activate a Biztalk Server Receive Location with e.g. a surveillance service. This may make sense if you use a POP3 Receive Location where the pop3 server casually is not reachable.

System.Management.ManagementObject requiredRLObj = null;
System.Management.ObjectGetOptions objGetOptions = new ObjectGetOptions();
System.Management.ManagementClass rlObjectClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_ReceiveLocation", objGetOptions);

System.Management.EnumerationOptions enumObjOptions = new EnumerationOptions();
enumObjOptions.ReturnImmediately = false;
System.Management.ManagementObjectCollection rlObjColl = rlObjectClass.GetInstances(enumObjOptions);

foreach (ManagementObject rlObjInstance in rlObjColl)
{
if (rlObjInstance["Name"] != null)
{
if (string.Compare("ReceiveLocationName", rlObjInstance["Name"].ToString(), true, System.Globalization.CultureInfo.CurrentUICulture) == 0)
{
requiredRLObj = rlObjInstance;
}
}
}

try
{
requiredRLObj.InvokeMethod("Disable", null);
requiredRLObj.InvokeMethod("Enable", null);
}
catch
{
Console.Write("Enabling Receive Location failed");
}

Receive attachments with content type text/xml via pop3

Receiving attachments via pop3 adapter of Microsoft Biztalk Server 2006 is possible using f.ex. an orchestration (www.commercelab.de/allgemeines/empfangen-von-emails-mit-attachment-und-speichern-der-angefugten-dateien-unter-ihrem-ursprunglichen-namen/). Receiving text/xml attachments you have to set the property BodyPart Contentelement in the pop3 configuration of your receive port to text/plain. With this options it is possible to receive any kind of attachments.

Without this configuration you wil get a XLANG error: WrongBodyPartException.

Receive EMails with Attachment and save the attached files under their original filename

Receiving EMails is possible using the pop3 adapter of Microsoft Biztalk Server 2006. But if you want to save multiple attachments with their original filename, you have to do a little detour with an orchestration.

Following process steps have to be defined:

  1. Create a new Biztalk Project with help of Visual Studio – Insert an new blank orchestration
  2. Definition of a unidirectional receive port with communication direction “I always receive messages on this port” and port binding “Define later”
  3. Definition of a unidirectional send port with communication direction “I always send messages on this port” and port binding “Define later”
  4. Definition of process and the variable nCount of type Int32 (Init value 1)
  5. Compile and provide the orchestration
  6. Create a receive port type POP3 with help of Biztalk Management Tool – Port Configuration with the credentials of you POP3 servers. Important is to set the option “MIME Decoding” to true
  7. Create a send port of type file (e.g.) with help of Biztalk Management Tool – Port Configuration. It is important using makro %SourceFileName%
  8. Activating ports, bind the ports to the orchestration
  9. Starting the orchestration

cc cc receive pop3 messages

Process step GetCount determine the amount of included attachments and save it to the variable nCount

//Set the input message to a var of XLang Message type
oXMessage = In;
// Get count
nCount = oXMessage.Count;

Process step MessageAssignment is called in a loop and transfers one attachment after the other to the send port. The original filename is transfered by MIME.FileName to the File.ReceivedFileName property of the send port, so that with help of the macro %SourceFileName% the original filename can be reused.

//Get the n'th part and set to a new message
Out = oXMessage[n];
Out(FILE.ReceivedFileName) = Out(MIME.FileName);
// Add to count
n = n + 1

Download of the Orchestration