为 Oracle 数据库配置客户端绑定

生成 WCF 客户端类后,可以创建 WCF 客户端 (实例) 并调用其方法来使用 Oracle 数据库适配器。 有关如何为 Microsoft BizTalk Adapter for Oracle Database 公开的操作生成 WCF 客户端类和帮助程序代码的信息,请参阅 为 Oracle 数据库解决方案项目生成 WCF 客户端或 WCF 服务协定

若要创建 WCF 客户端,必须指定终结点地址和绑定。 终结点地址必须包含有效的 Oracle 连接 URI,并且绑定必须是 Oracle DB 绑定 (OracleDBBinding) 的实例。 有关 Oracle 连接 URI 的详细信息,请参阅 创建 Oracle 数据库连接 URI。 建议不要将用户凭据指定为连接 URI 的一部分。 可以改用 WCF 客户端的 ClientCredentials 属性,如本主题中所述。

可以在代码或配置文件中指定 Oracle DB 绑定和终结点地址。 使用添加适配器服务引用 Visual Studio 插件生成 WCF 客户端类时,还会为项目创建配置文件 (app.config) 。 此文件包含的配置设置反映绑定属性和连接信息 (,但凭据) 除外,这些凭据是使用“添加适配器服务引用”插件连接到 Oracle 数据库时指定的。

在代码中指定绑定和终结点地址

以下代码演示如何通过在代码中指定绑定和终结点地址来创建 WCF 客户端。 最好使用 WCF 客户端的 ClientCredentials 属性指定 Oracle 凭据,而不是在为终结点地址提供的连接 URI 中指定 Oracle 凭据。

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

在配置文件中指定绑定和终结点地址

以下代码演示如何通过在 app.config 文件中指定绑定和终结点地址来创建 WCF 客户端。

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

以下 XML 显示通过添加适配器服务引用插件为 EMP 表创建的配置文件。 此文件包含前面示例中引用的客户端终结点配置。

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

如果一个项目有多个 WCF 客户端,配置文件中将定义多个客户端终结点条目。 每个 WCF 客户端条目将根据其绑定配置和目标 Oracle 数据库项目具有唯一的名称;例如,“OracleDBBinding_SCOTT.Table.EMP”。 如果多次连接以在项目中创建 WCF 客户端,则会创建多个绑定配置条目,每个连接一个。 这些绑定配置条目将按以下方式命名:OracleDBBinding1、OracleDBBinding2 等。 在特定连接期间创建的每个客户端终结点条目都将引用在该连接期间创建的绑定条目。

另请参阅

使用 WCF 服务模型开发 Oracle 数据库应用程序
为 Oracle 数据库解决方案项目生成 WCF 客户端或 WCF 服务协定
创建 Oracle 数据库连接 URI
使用 WCF 通道模型开发 Oracle 数据库应用程序