다음을 통해 공유


BAM API를 사용하여 BAM 인터셉터 로드

이 항목에서는 구성 파일을 통하지 않고 코드에서 WF 및 WCF 인터셉터를 로드하는 방법에 대한 정보를 제공합니다.

주의

이 예제 또는 지침은 연결 문자열 또는 사용자 이름 및 암호와 같은 중요한 정보를 참조합니다. 코드에서 이러한 값을 하드 코딩하지 않으며 사용 가능한 가장 안전한 인증을 사용하여 기밀 데이터를 보호해야 합니다. 자세한 내용은 다음 설명서를 참조하세요.

코드에서 WF 인터셉터를 로드하기

코드에서 WF 인터셉터 런타임을 로드하려면 WorkflowRuntime의 새 인스턴스를 만들고 BamTrackingService의 새 인스턴스를 사용하여 AddService 메서드를 호출해야 합니다. 아래에 설명되어 있습니다.

string connectionString = "Integrated Security=SSPI;Data Source=.;Initial Catalog=BAMPrimaryImport";  
int PollingIntervalSec = 300;  
  
WorkflowRuntime workflowRuntime = new WorkflowRuntime();  
workflowRuntime.AddService(new BamTrackingService(connectionString, interceptorConfigurationPollingInterval));  

코드에서 WCF 인터셉터 로드

WCF 인터셉터를 로드하려면 서비스를 열고 구현에 액세스할 수 있는 파생 클래스를 만들어야 합니다. 아래에 설명되어 있습니다.

// 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);  
}  

또한 참조하십시오

BAM WCF 및 WF 인터셉터 사용