Chargement des intercepteurs BAM à l'aide de l'API BAM
Cette rubrique fournit des informations sur le chargement des intercepteurs WF et WCF à partir de votre code plutôt que par l'utilisation d'un fichier de configuration.
Chargement de l'intercepteur WF à partir d'un code
Pour charger le composant d'exécution de l'intercepteur WF à partir d'un code, vous devez créer une instance de WorkflowRuntime, puis appeler la méthode AddService avec une nouvelle instance de BamTrackingService. Cette opération est illustrée ci-dessous.
string connectionString = "Integrated Security=SSPI;Data Source=.;Initial Catalog=BAMPrimaryImport";
int PollingIntervalSec = 300;
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
workflowRuntime.AddService(new BamTrackingService(connectionString, interceptorConfigurationPollingInterval));
Chargement de l'intercepteur WCF à partir d'un code
Pour charger l'intercepteur WCF, vous devez créer une classe dérivée qui est chargée d'ouvrir le service et qui est accessible à votre implémentation. Cette opération est illustrée ci-dessous.
// Your project must have a reference to Microsoft.BizTalk.BAM.Interceptors.dll.
// Create a derived class accessible to the implementation that opens the service.
internal class MyBamBehaviorExtension : BamBehaviorExtension
{
internal MyBamBehaviorExtension(string connectionString, int pollingInterval)
: base()
{
this.ConnectionString = connectionString;
this.PollingIntervalSec = pollingInterval.ToString();
}
internal IEndpointBehavior Create()
{
return (IEndpointBehavior) this.CreateBehavior();
}
}
// Add the endpoint behavior just before the service is opened.
// In this example the connection string and polling intervals are being read from appSettings in App.config.
MyBamBehaviorExtension bamBehaviorExtension = new MyBamBehaviorExtension(ConfigurationManager.AppSettings["ConnectionString"], int.Parse(ConfigurationManager.AppSettings["PollingIntervalSec"]));
IEndpointBehavior bamBehavior = bamBehaviorExtension.Create();
foreach (System.ServiceModel.Description.ServiceEndpoint endpoint in myServiceHost.Description.Endpoints)
{
if (endpoint.Behaviors.Find<MyBamBehaviorExtension>() == null)
endpoint.Behaviors.Add(bamBehavior);
}