SAP を使用してチャネルを作成する

WCF チャネル モデルでは、SAP システムに対する操作を呼び出すか、WCF チャネル経由で Microsoft BizTalk Adapter for mySAP Business Suite と SOAP メッセージを交換することで、SAP システムからメッセージを受信します。

  • IRequestChannel または IOutputChannel を使用してアダプターにメッセージを送信することで、操作 (送信操作) を呼び出します

  • IReplyChannel 経由で (SAP システムからトリガーされた) メッセージを受信します。

    このセクションのトピックでは、受信および送信操作に使用されるチャネル図形を作成および構成する方法について説明します。

送信 (クライアント) チャネルの作成

IRequestChannel または IOutputChannel を使用して、SAP システムに対する操作を呼び出すことができます。 どちらの場合も、最初に適切なインターフェイスを使用して System.ServiceModel.ChannelFactory を作成します。 次に、ファクトリを使用してチャネルを作成します。 チャネルを作成したら、それを使用してアダプターに対する操作を呼び出すことができます。

送信チャネルを作成して開くには

  1. エンドポイントとバインドを使用して、目的のチャネル図形の ChannelFactory のインスタンスを作成して初期化します。 エンドポイントは SAP 接続 URI を指定し、バインドは SAPDBBinding のインスタンスです。 (チャネル ファクトリを開く前に必要なバインド プロパティを設定します)。

  2. ClientCredentials プロパティを使用して、チャネル ファクトリの SAP 資格情報を指定します。

  3. チャネル ファクトリを開きます。

  4. チャネル ファクトリで CreateChannel メソッドを呼び出して、チャネルのインスタンスを取得します。

  5. チャネルを開きます。

    コードまたは構成からバインディングとエンドポイント アドレスを指定できます。

コードでのバインディングアドレスとエンドポイントアドレスの指定

次のコード例は、コードでバインドとエンドポイント アドレスを指定して IRequestChannel を作成する方法を示しています。 IOutputChannel を作成するコードは同じですが、ChannelFactory とチャネルの種類に IOutputChannel インターフェイスを指定する必要があります。

// Create binding -- set binding properties before you open the factory.  
SAPBinding sapBinding = new SAPBinding();  
  
// Create address.  
EndpointAddress sapAddress = new EndpointAddress("sap://Client=800;lang=EN@A/YourSAPHost/00");  
  
// Create channel factory from binding and address.  
ChannelFactory<IRequestChannel> factory =   
    new ChannelFactory<IRequestChannel>(sapBinding, sapAddress);  
  
// Specify credentials.   
factory.Credentials.UserName.UserName = "YourUserName";  
factory.Credentials.UserName.Password = "YourPassword";  
  
// Open the factory  
factory.Open();  
  
// Get channel and open it.  
IRequestChannel channel = factory.CreateChannel();  
channel.Open();  

構成でのバインディングとエンドポイント アドレスの指定

次のコード例は、構成で指定されたクライアント エンドポイントからチャネル ファクトリを作成する方法を示しています。

// Create channel factory from configuration.  
ChannelFactory<IRequestChannel> factory =  
new ChannelFactory<IRequestChannel>("MyRequestChannel");  
  
// Specify credentials.  
factory.Credentials.UserName.UserName = "YourUserName";  
factory.Credentials.UserName.Password = "YourPassword";  
  
// Open the factory.  
factory.Open();  
  
// Get a channel and open it.  
IRequestChannel channel = factory.CreateChannel();  
channel.Open();  

構成設定

次のコードは、前の例で使用した構成設定を示しています。 クライアント エンドポイントのコントラクトは、作成するチャネル図形の種類に応じて、"System.ServiceModel.Channels.IRequestChannel" または "System.ServiceModel.Channels.IRequestChannel" である必要があります。

<?xml version="1.0" encoding="utf-8"?>  
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">  
    <system.serviceModel>  
        <bindings>  
            <sapBinding>  
                <binding name="SAPBinding" closeTimeout="00:01:00" openTimeout="00:01:00"  
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" enableBizTalkCompatibilityMode="false"  
                    receiveIdocFormat="Typed" enableSafeTyping="false" generateFlatFileCompatibleIdocSchema="true"  
                    maxConnectionsPerSystem="50" enableConnectionPooling="true"  
                    idleConnectionTimeout="00:15:00" flatFileSegmentIndicator="SegmentDefinition"  
                    enablePerformanceCounters="false" autoConfirmSentIdocs="false"  
                    acceptCredentialsInUri="false"  
                    padReceivedIdocWithSpaces="false" sncLibrary="" sncPartnerName="" />  
            </sapBinding>  
        </bindings>  
        <client>  
            <endpoint address="sap://CLIENT=800;LANG=EN;@a/ADAPSAP47/00?RfcSdkTrace=False&AbapDebug=False"  
                binding="sapBinding" bindingConfiguration="SAPBinding" contract="System.ServiceModel.Channels.IRequestChannel"  
                name="MyRequestChannel" />  
        </client>  
    </system.serviceModel>  
</configuration>  

受信 (サービス) チャネルの作成

SAPBinding のインスタンスにバインド プロパティを設定することで、SAP システムから受信メッセージを受信するようにアダプター を構成します。 次に、このバインディングを使用して、アダプターから操作を受信する IReplyChannel チャネルを取得できるチャネル リスナーを構築します。

IReplyChannel を作成して開いてデータ変更通知を受信するには
  1. SAPBinding のインスタンスを作成します。

  2. 受け取る操作に必要なバインディング プロパティを設定します。 AcceptCredentialsInUri バインド プロパティを必ず設定してください。

  3. BindingParameterCollection を作成し、受信する操作のアクションを含む InboundActionCollection を追加します。 アダプターは、他のすべての操作について SAP システムに例外を返します。 この手順は省略可能です。 詳細については、「 WCF チャネル モデルを使用した SAP システムからの受信操作の受信」を参照してください。

  4. SAPBindingBuildChannelListener<IReplyChannel メソッドを呼び出して、>チャネル リスナーを作成します。 SAP 接続 URI は、このメソッドのパラメーターの 1 つとして指定します。 接続 URI には、SAP システム上の RFC 宛先のパラメーターが含まれている必要があります。 SAP 接続 URI の詳細については、「SAP システム接続 URI の作成」を参照してください。 手順 3 で BindingParameterCollection を 作成した場合は、チャネル リスナーを作成するときにもこれを指定します。

  5. リスナーを開きます。

  6. リスナーで AcceptChannel メソッドを呼び出して、IReplyChannel チャネルを取得します。

  7. チャネルを開きます。

    次のコードは、チャネル リスナーを作成し、アダプターから操作を受信する IReplyChannel を取得する方法を示しています。

// Create a binding and specify any binding properties required  
// for the opreations you want to receive  
SAPBinding binding = new SAPBinding();  
  
// Set AcceptCredentialsInUri because the URI must contain credentials.  
binding.AcceptCredentialsInUri = true;  
  
// Create an InboundActionCollection and add the message actions to listen for,  
// only the actions added to the InboundActionCollection are received on the channel.  
// In this case a single action is specified: http://Microsoft.LobServices.Sap/2007/03/Rfc/Z_RFC_MKD_ADD  
InboundActionCollection actions = new InboundActionCollection(listeneraddress);  
actions.Add("http://Microsoft.LobServices.Sap/2007/03/Rfc/Z_RFC_MKD_ADD");  
  
// Create a BindingParameterCollection and add the InboundActionCollection  
BindingParameterCollection bpcol = new BindingParameterCollection();  
bpcol.Add(actions);  
  
// Create the channel listener by specifying  
// the binding parameter collection (to filter for the Z_RFC_MKD_ADD action) and   
// a connection URI that contains listener parameters.  
Uri listeneraddress =  
new Uri("sap://User=YourUserName;Passwd=YourPassword;Client=800;Lang=EN;@a/YourSAPHost/00?ListenerGwServ=SAPGATEWAY&ListenerGwHost=YourSAPHost&ListenerProgramId=SAPAdapter");  
listener = binding.BuildChannelListener<IReplyChannel>(connectionUri, new BindingParameterCollection());  
listener.Open();  
  
// Get a channel from the listener and open it.  
channel = listener.AcceptChannel();  
channel.Open();  

参照

WCF チャネル モデルを使用してアプリケーションを開発する