我正在使用WMI创建不同类型的DNS记录,但是SRV记录有问题。每当我传递domainname参数时,我都会遇到“找不到的”错误。域名对我来说很好。

有人成功地做到了吗?

这是我的代码:

internal static void CreateSrvRecordInDns(string Zone, string OwnerName, string DomainName, UInt16 Weight, UInt16 Priority, UInt16 Port)
    {
        DnsProvider dns = new DnsProvider();
        ManagementClass mClass = new ManagementClass(dns.Session, new ManagementPath("MicrosoftDNS_SrvType"), null);
        ManagementBaseObject inParams = mClass.GetMethodParameters("CreateInstanceFromPropertyData");
        inParams["DnsServerName"] = dns.Server;
        inParams["ContainerName"] = Zone;
        inParams["OwnerName"] = OwnerName;
        inParams["DomainName"] = DomainName; //Error occurs here
        inParams["Port"] = Port;
        inParams["Priority"] = Priority;
        inParams["Weight"] = Weight;
        mClass.InvokeMethod("CreateInstanceFromPropertyData", inParams, null);
        dns.Dispose(ref inParams);
        dns.Dispose(ref mClass);
    }
有帮助吗?

解决方案

只需用以下方式替换有问题的行

inParams["SRVDomainName"] = DomainName;

我不知道原因,但是当获得属性列表时:

PropertyData[] pd = new PropertyData[inParams.Properties.Count];
inParams.Properties.CopyTo(pd,0);

这是此字段的名称(Microsoft的错误?)

Hth。

PS为了查看每个字段的正确格式,请使用WBEMTEST工具(WBEMTEST从命令提示符),连接到root microsoftdns名称空间并运行以下查询:

Select * from MicrosoftDNS_SRVType

您应该使用与答案中列出的实例相同的格式)。

其他提示

我想在这里为那些仍然无法获得它的人添加一些细节...

如果你的 域名Google.com 如果是 记录 是 : _finger._tcp.google.com 指向 目标主机 : 你好。google.com 然后,变量及其值将如下:

    inParams["DnsServerName"] = dns.Server;
    inParams["ContainerName"] = Zone; //google.com
    inParams["OwnerName"] = OwnerName; //_finger._tcp.google.com
    // Can't set domain name like this, leave this field
    //inParams["DomainName"] = DomainName; //_tcp.google.com
    //Set Target SRV Host here which is providing the service,,,
    inParams["SRVDomainName"] = DomainName; //target Host : hello.google.com

    inParams["Port"] = Port;
    inParams["Priority"] = Priority;
    inParams["Weight"] = Weight;

我已经通过创建示例应用程序和创建Zone google.com并设置SRV记录及其值,从而进行了测试。我希望这有助于那些对其他答复听起来不太解释的人。

正确的SRV记录是 _finger._tcp.example.com.

我不知道WMI,但是系统可能要求您为 _tcp.example.com 第一的。

编辑

我相信我现在看到了问题 - 你 OwnerName 字段应该是要包含的一个 _finger._tcp.example.com. 。这 DomainName 字段应该包含 目标SRV 记录。

http://msdn.microsoft.com/en-us/library/ms682736%28v=vs.85%29.aspx

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top