如何在使用托管 ODP.NET 时从 C# 查询 LDAP 以解析 Oracle TNS 主机名? [英] How do I query LDAP from C# to resolve Oracle TNS hostname while using managed ODP.NET?

查看:21
本文介绍了如何在使用托管 ODP.NET 时从 C# 查询 LDAP 以解析 Oracle TNS 主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我之前的 问题 的基础上,我设法用 来自 Oracle 论坛的帮助,我现在遇到了另一个问题,这是上一个问题的后续问题(提供背景信息).

Further to my previous Question, which I managed to answer myself with help from the Oracle forums, I now have another issue which follows on from the earlier one (provided for background).

我希望直接从我的 C# 代码中查询 LDAP,以执行 Oracle TNS 主机名的 LDAP 查找,以获取连接字符串.这通常存储在 tnsnames.ora 中,我的组织使用 LDAP(通过 ldap.ora)从使用 Active Directory 的 LDAP 服务器解析主机名.

I wish to query LDAP directly from my C# code to perform an LDAP lookup of an Oracle TNS hostname in order to get the connection string. This is normally stored in tnsnames.ora, and my organisation uses LDAP (via ldap.ora) to resolve hostnames from an LDAP server using Active Directory.

但是,我使用的是 ODP.NET,托管驱动程序测试版 (Oracle.ManagedDataAccess.dll) 在我的 C# 应用程序中,它不支持 发行说明"nofollow noreferrer">Oracle 论坛回复 前面提到过.这就是为什么我希望直接从 C# 中查询 LDAP.

However, I am using ODP.NET, Managed Driver Beta (Oracle.ManagedDataAccess.dll) in my C# application which doesn't support LDAP as mentioned in the release notes pointed to by the Oracle forum reply I mentioned earlier. This is why I wish to query LDAP directly from C#.

我在这里找到了一种方法,使用 DirectoryEntryDirectorySearcher,但我不知道将什么作为参数放入 DirectorySearcher.我可以访问 ldap.ora,格式如下:

I found a way to do this here using DirectoryEntry and DirectorySearcher, but I have no idea what to put as the parameters to DirectorySearcher. I have access to ldap.ora which is in the following format:

# LDAP.ORA 配置
# 由 Oracle 配置工具生成.
DEFAULT_ADMIN_CONTEXT = "dc=xx,dc=mycompany,dc=com"
DIRECTORY_SERVERS = (ldap_server1.mycompany.com:389:636,ldap_server2.mycompany.com:389:636, ...) DIRECTORY_SERVER_TYPE = OID

# LDAP.ORA Configuration
# Generated by Oracle configuration tools.
DEFAULT_ADMIN_CONTEXT = "dc=xx,dc=mycompany,dc=com"
DIRECTORY_SERVERS = (ldap_server1.mycompany.com:389:636,ldap_server2.mycompany.com:389:636, ...) DIRECTORY_SERVER_TYPE = OID

但是,如何将其映射到在我的 C# 代码中设置 LDAP 查询?

But, how do I map this to setting up the LDAP query in my C# code?

推荐答案

根据我在 使用 OpenLDAP 进行 Oracle 数据库名称解析,代码应如下所示:

Judging by what I found in Oracle Database Name Resolution with OpenLDAP, the code should look something like this:

string directoryServer = "ldap_server1.mycompany.com:389";
string defaultAdminContext = "dc=xx,dc=mycompany,dc=com";
string oracleHostEntryPath = string.Format("LDAP://{0}/cn=OracleContext,{1}", directoryServer, defaultAdminContext);

var directoryEntry = new DirectoryEntry(oracleHostEntryPath) {AuthenticationType = AuthenticationTypes.None};
var directorySearcher = new DirectorySearcher(directoryEntry, "(&(objectclass=orclNetService)(cn=ABCDEFG1))", new[] { "orclnetdescstring" }, SearchScope.Subtree);

string oracleNetDescription = Encoding.Default.GetString(des.FindOne().Properties["orclnetdescstring"][0] as byte[]);

这篇关于如何在使用托管 ODP.NET 时从 C# 查询 LDAP 以解析 Oracle TNS 主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆