Editar

Partilhar via


Create a channel using Oracle Database

In the WCF channel model, you invoke operations on the Oracle database and receive the results of a polling query by exchanging SOAP messages with the Microsoft BizTalk Adapter for Oracle Database over a WCF channel.

  • You invoke operations (outbound operations) by using either an IRequestChannel or an IOutputChannel to send messages to the adapter.

  • You receive polling-based data-changed messages by receiving POLLINGSTMT messages over an IInputChannel.

    The topics in this section provide information about how to create and configure channel shapes that are used for inbound and outbound operations.

Creating Outbound (Client) Channels

You can use either an IRequestChannel or an IOutputChannel to invoke operations on the Oracle database. In either case, you first create a System.ServiceModel.ChannelFactory using the appropriate interface. You then use the factory to create the channel. After you have created the channel you can use it to invoke operations on the adapter.

To create and open an outbound channel

  1. Create and initialize an instance of ChannelFactory for the desired channel shape by using an endpoint and a binding. The endpoint specifies an Oracle connection URI and the binding is an instance of OracleDBBinding.

  2. Provide Oracle credentials for the channel factory by using the Credentials property.

  3. Open the channel factory.

  4. Get an instance of the channel by invoking the CreateChannel method on the channel factory.

  5. Open the channel.

    You can specify the binding and endpoint address in your code or from configuration.

Specifying the Binding and Endpoint Address in Code

The following code example shows how to create an IRequestChannel by specifying the binding and endpoint address in code. The code to create an IOutputChannel is the same except that you must specify an IOutputChannel interface for the ChannelFactory and channel type.

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

Specifying the Binding and Endpoint Address in Configuration

The following code example shows how to create a channel factory from a client endpoint specified in configuration.

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

The Configuration Settings

The following code shows the configuration settings used for the preceding example. The contract for the client endpoint must be "System.ServiceModel.Channels.IRequestChannel" or "System.ServiceModel.Channels.IRequestChannel" depending on the kind of channel shape that you want to create.

<?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>  

Creating Inbound (Service) Channels

You configure the Oracle Database adapter to poll the Oracle database tables and views by setting binding properties on an instance of OracleDBBinding. You then use this binding to build a channel listener from which you can get an IInputChannel channel to receive message for inbound operations from the adapter.

To create and open an IInputChannel to receive messages for inbound operations
  1. Create an instance of OracleDBBinding.

  2. Set the binding properties required for the inbound operation. For example, for the POLLINGSTMT operation, at a minimum you must set the InboundOperationType, PollingStatement, and PollingInterval binding properties to configure the Oracle Database adapter to poll the Oracle database.

  3. Create a binding parameter collection using the BindingParameterCollection class and set the credentials.

  4. Create a channel listener by invoking BuildChannelListener<IInputChannel> method on the OracleDBBinding. You specify the Oracle connection URI as one of the parameters to this method. For more information about the Oracle connection URI, see Create the Oracle Database connection URI.

  5. Open the listener.

  6. Get an IInputChannel channel by invoking the AcceptChannel method on listener.

  7. Open the channel.

    The following code shows how to create a channel listener and get an IInputChannel to inbound messages from the adapter using the POLLINGSTMT operation.

Note

The Oracle Database adapter only supports one-way receive. So, you must use IInputChannel to receive messages for inbound operations from Oracle database.

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

See Also

Develop Oracle Database applications using the WCF Channel Model