サービスの動作を使用して、WCF LOB アダプター SDK で資格情報を入力する
多くの場合、アダプター コンシューマーは、ターゲット基幹業務システムに資格情報を渡す必要があります。 この機能を提供するには、WCF サービスの動作を指定する必要があります。
次のコード例は、サービスの動作を派生させる方法を示しています。 アダプターのコンシューマーから取得した資格情報をアダプターに委任します。 その後、アダプターは基幹業務プロトコルを使用して資格情報を認証する必要があります。 資格情報が認証されると、サービスは基幹業務アプリケーションからの受信イベントのリッスンを開始できます。
/// <summary>
/// This class derives from a WCF service behavior. It is used in the inbound scenario
/// for the Inbound Service to pass the line-of-business credentials to the adapter using
/// WCF ClientCredentials class.
/// </summary>
public class InboundClientCredentialsServiceBehavior : ClientCredentials, IServiceBehavior
{
public InboundClientCredentialsServiceBehavior() { }
public InboundClientCredentialsServiceBehavior(InboundClientCredentialsServiceBehavior other)
: base(other)
{
}
#region IServiceBehavior Members
public void AddBindingParameters(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
bindingParameters.Add(this);
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
{
}
public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
{
}
#endregion
protected override ClientCredentials CloneCore()
{
return new InboundClientCredentialsServiceBehavior(this);
}
}
次のコード例は、サービスの動作を使用して資格情報をアダプターに渡す方法を示しています。
// Create a ServiceHost for the EchoServiceImpl type
// and use the base address from app.config
ServiceHost host = new ServiceHost(typeof(EchoServiceImpl));
// Set service behavior to pass the line-of-business credentials.
InboundClientCredentialsServiceBehavior credentialsBehavior = new InboundClientCredentialsServiceBehavior();
credentialsBehavior.UserName.UserName = "username";
credentialsBehavior.UserName.Password = "****";
host.Description.Behaviors.Add(credentialsBehavior);
// Open the ServiceHost to start listening for messages
host.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.ReadLine();
// Close the ServiceHost
host.Close();