Configure a client binding for the Oracle Database

After you have generated the WCF client class, you can create a WCF client (instance) and invoke its methods to consume the Oracle Database adapter. For information about how to generate the WCF client class and helper code for operations that the Microsoft BizTalk Adapter for Oracle Database exposes, see Generate a WCF Client or a WCF Service Contract for Oracle Database Solution Artifacts.

To create the WCF client, you must specify an endpoint address and a binding. The endpoint address must contain a valid Oracle connection URI, and the binding must be an instance of an Oracle DB Binding (OracleDBBinding). For more information about the Oracle connection URI, see Create the Oracle Database Connection URI. We recommend that you do not specify the user credentials as part of the connection URI. You may instead use the ClientCredentials property of the WCF client, as explained in this topic.

You can specify the Oracle DB Binding and the endpoint address in your code or in a configuration file. When you use the Add Adapter Service Reference Visual Studio Plug-in to generate the WCF client class, a configuration file (app.config) is also created for your project. This file contains configuration settings that reflect the binding properties and connection information (except credentials) that you specified when you connected to the Oracle database with the Add Adapter Service Reference Plug-in.

Specifying the Binding and Endpoint Address in Code

The following code shows how to create a WCF client by specifying the binding and endpoint address in code. It is good practice to specify the Oracle credentials by using the ClientCredentials property of the WCF client rather than in the connection URI supplied for the endpoint address.

// A WCF client that targets the /SCOTT/EMP table is created  
// by using a binding object and endpoint address  
OracleDBBinding odbBinding = new OracleDBBinding();  
EndpointAddress odbAddress = new EndpointAddress("OracleDb://ADAPTER");  
  
SCOTTTableEMPClient empClient = new SCOTTTableEMPClient(odbBinding, odbAddress);  
  
empClient.ClientCredentials.UserName.UserName = "SCOTT";  
empClient.ClientCredentials.UserName.Password = "TIGER";  
  
empClient.Open();  

Specifying the Binding and Endpoint Address in a Configuration File

The following code shows how to create a WCF client by specifying the binding and endpoint address in an app.config file.

// A WCF client that targets the /SCOTT/EMP table is created  
// by specifying the client endpoint information in app.config  
SCOTTTableEMPClient empClient = new SCOTTTableEMPClient("OracleDBBinding_SCOTT.Table.EMP");  
  
empClient.ClientCredentials.UserName.UserName = "SCOTT";  
empClient.ClientCredentials.UserName.Password = "TIGER";  
  
empClient.Open();  

The following XML shows the configuration file created for the EMP table by the Add Adapter Service Reference Plug-in. This file contains the client endpoint configuration referenced in the preceding example.

\<?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"  
                    dataFetchSize="65536" metadataPooling="true" statementCachePurge="false"  
                    statementCacheSize="10" longDatatypeColumnSize="32767" pollingStatement=""  
                    postPollStatement="" pollingInterval="500" useOracleConnectionPool="false"  
                    minPoolSize="1" maxPoolSize="100" incrPoolSize="5" decrPoolSize="1"  
                    connectionLifetime="0" transactionIsolationLevel="ReadCommitted"  
                    enablePerformanceCounters="false" acceptCredentialsInUri="false"  
                    enableBizTalkCompatibilityMode="false" />  
            </oracleDBBinding>  
        </bindings>  
        <client>  
            <endpoint address="oracledb://adapter/" binding="oracleDBBinding"  
                bindingConfiguration="OracleDBBinding" contract="SCOTTTableEMP"  
                name="OracleDBBinding_SCOTT.Table.EMP" />  
        </client>  
    \</system.serviceModel>  
</configuration>  

If a project has more than one WCF client, there will be multiple client endpoint entries defined in the configuration file. Each WCF client entry will have a unique name based on its binding configuration and target Oracle database artifact; for example, "OracleDBBinding_SCOTT.Table.EMP". If you connect multiple times to create the WCF clients in your project, multiple binding configuration entries will be created, one for each connection. These binding configuration entries will be named in the following manner: OracleDBBinding1, OracleDBBinding2, and so on. Each client endpoint entry created during a specific connection will reference the binding entry created during that connection.

See Also

Develop Oracle Database Applications by Using the WCF Service Model
Generate a WCF Client or a WCF Service Contract for Oracle Database Solution Artifacts
Create the Oracle Database Connection URI
Develop Oracle Database Applications by Using the WCF Channel Model