共用方式為


使用 Oracle Database 建立通道

在 WCF 通道模型中,您會在 Oracle 資料庫上叫用作業,並透過 WCF 通道與 Microsoft bizTalk Adapter for Oracle Database 交換 SOAP 訊息,以接收輪詢查詢的結果。

  • 您可以使用 IRequestChannelIOutputChannel 來將訊息傳送至配接器來叫用作業(輸出作業)。

  • 透過 IInputChannel 接收 POLLINGSTMT 訊息,即可接收輪詢式數據變更訊息。

    本節中的主題提供如何建立及設定用於輸入和輸出作業的通道圖形的相關信息。

建立用戶端外部通道

您可以使用 IRequestChannelIOutputChannel 來叫用 Oracle 資料庫的作業。 不論是哪一種情況,您都先使用適當的介面來建立 System.ServiceModel.ChannelFactory 。 然後,您可以使用工廠來創建通道。 建立通道後,您可以使用它來调用适配器上的操作。

建立和開啟輸出通道

  1. 使用端點和系結,建立及初始化所需通道圖形的 ChannelFactory 實例。 端點會指定 Oracle 連線 URI,而系結是 OracleDBBinding 的實例。

  2. 使用 Credentials 屬性為通道處理站提供 Oracle 認證

  3. 開啟通道處理站。

  4. 在通道處理站上叫用 CreateChannel 方法,以取得通道的實例。

  5. 開啟通道。

    您可以在程式代碼或組態中指定系結和端點位址。

在程式代碼中指定系結和端點位址

下列程式代碼範例示範如何在程式代碼中指定系結和端點位址,以建立 IRequestChannel 。 若要建立 IOutputChannel 的程式代碼相同,不同之處在於您必須為 ChannelFactory 和通道類型指定 IOutputChannel 介面。

// Create binding -- set binding properties before you open the factory.  
OracleDBBinding odbBinding = new OracleDBBinding();  
  
// Create address.  
EndpointAddress odbAddress = new EndpointAddress("oracledb://ADAPTER/");  
  
// Create channel factory from binding and address.  
ChannelFactory<IRequestChannel> factory =   
    new ChannelFactory<IRequestChannel>(odbBinding, odbAddress);  
  
// Specify credentials.   
factory.Credentials.UserName.UserName = "SCOTT";  
factory.Credentials.UserName.Password = "TIGER";  
  
// Open 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 = "SCOTT";  
factory.Credentials.UserName.Password = "TIGER";  
  
// 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>  
            <oracleDBBinding>  
                <binding name="OracleDBBinding" closeTimeout="00:01:00" openTimeout="00:01:00"  
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" metadataPooling="true"  
                    statementCachePurge="false" statementCacheSize="10" pollingInterval="500"  
                    useOracleConnectionPool="true" minPoolSize="1" maxPoolSize="100"  
                    incrPoolSize="5" decrPoolSize="1" connectionLifetime="0" acceptCredentialsInUri="false"  
                    useAmbientTransaction="true" polledDataAvailableStatement="SELECT 1 FROM DUAL"  
                    pollWhileDataFound="false" notifyOnListenerStart="true" notificationPort="-1"  
                    inboundOperationType="Polling" dataFetchSize="65536" longDatatypeColumnSize="0"  
                    skipNilNodes="true" maxOutputAssociativeArrayElements="32"  
                    enableSafeTyping="false" insertBatchSize="1" useSchemaInNameSpace="true"  
                    enableBizTalkCompatibilityMode="false" enablePerformanceCounters="false" />  
            </oracleDBBinding>  
        </bindings>  
        <client>  
            <endpoint address="oracledb://adapter/" binding="oracleDBBinding"  
                bindingConfiguration="OracleDBBinding" contract="System.ServiceModel.Channels.IRequestChannel"  
                name="MyRequestChannel" />  
        </client>  
    </system.serviceModel>  
</configuration>  

建立輸入 (服務) 通道

您設定 Oracle Database 配接器,通過在 OracleDBBinding 實例上設定繫結屬性,對 Oracle 資料庫的表和視圖進行輪詢。 接著,您可以使用此系結來建置一個通道接聽程式,透過它您可以取得 IInputChannel 通道,以接收來自適配器的輸入作業訊息。

建立並開啟 IInputChannel 以接收輸入作業的訊息
  1. 建立 OracleDBBinding 的實例。

  2. 設定輸入作業所需的系結屬性。 例如,針對 POLLINGSTMT 作業,您至少必須設定 InboundOperationTypePollingStatementPollingInterval 系結屬性,以設定 Oracle 資料庫配接器來輪詢 Oracle 資料庫。

  3. 使用 BindingParameterCollection 類別建立係結參數集合,並設定認證。

  4. OracleDBBinding 上叫用 BuildChannelListener<IInputChannel> 方法,以建立通道接聽程式。 您可以將 Oracle 連線 URI 指定為此方法的其中一個參數。 如需 Oracle 連線 URI 的詳細資訊,請參閱 建立 Oracle 資料庫連線 URI

  5. 開啟接聽程式。

  6. 在接聽程式上叫用 AcceptChannel 方法,以取得 IInputChannel 通道。

  7. 開啟通道。

    下列程式代碼示範如何建立通道監聽器,並使用 POLLINGSTMT 作業,從適配器取得一個 IInputChannel 來接收輸入訊息。

備註

Oracle 資料庫配接器僅支援單向接收。 因此,您必須使用 IInputChannel 從 Oracle 資料庫接收輸入作業的訊息。

// Create a binding: specify the InboundOperationType, PollingInterval (in seconds), the PollingStatement, and  
// the PostPollStatement.  
OracleDBBinding binding = new OracleDBBinding();  
binding.InboundOperationType = InboundOperation.Polling;  
binding.PollingInterval = 30;  
binding.PollingStatement = "SELECT * FROM ACCOUNTACTIVITY FOR UPDATE";  
binding.PostPollStatement = "BEGIN ACCOUNT_PKG.PROCESS_ACTIVITY(); END;";  
  
// Create a binding parameter collection and set the credentials  
ClientCredentials credentials = new ClientCredentials();  
credentials.UserName.UserName = "SCOTT";  
credentials.UserName.Password = "TIGER";  
  
BindingParameterCollection bindingParams = new BindingParameterCollection();  
bindingParams.Add(credentials);  
  
// Get a listener from the binding and open it.  
Uri connectionUri = new Uri("oracleDB://ADAPTER");  
IChannelListener<IInputChannel> listener = binding.BuildChannelListener<IInputChannel>(connectionUri, bindingParams);  
listener.Open();  
  
// Get a channel from the listener and open it.  
channel = listener.AcceptChannel();  
channel.Open();  

另請參閱

使用 WCF 通道模型開發 Oracle 資料庫應用程式