2010-09-22 64 views
8

我正在使用WMI創建不同類型的DNS記錄,但遇到SRV記錄問題。每當我通過DomainName參數時,我總是收到「未找到」錯誤。該域名看起來不錯。如何使用C#在DNS中創建SRV記錄

有沒有人曾經成功地做過這件事?

這裏是我的代碼:

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); 
    } 
+0

你傳遞的域名是什麼? – CodingGorilla 2010-09-22 18:55:25

+0

_tcp._finger。parentdomain – mcass20 2010-09-22 18:57:50

+0

你的意思是* _finger._tcp.parentdomain *? [rfc2782](http://tools.ietf.org/html/rfc2782) – dtb 2010-09-22 19:00:18

回答

4

只需將其替換有問題的行:

inParams["SRVDomainName"] = DomainName; 

我不知道原因,但是當拿到屬性列表:

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

這是名(微軟的bug?)

HTH。

P.S.爲了看到每個字段的正確的格式,使用WBEMTEST工具(從命令提示符WBEMTEST),連接到root \ MicrosoftDNS命名空間,運行以下查詢:

Select * from MicrosoftDNS_SRVType 

您應該使用相同的格式實例上市在答案中)。

+0

謝謝!對於這兩個解決方案,並引起我的注意wbemtest工具。 – mcass20 2010-10-05 15:40:16

0

正確的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

+0

感謝您的建議。我已經嘗試創建域名,但無濟於事。當我嘗試傳遞DomainName參數時,我仍然收到相同的錯誤。 – mcass20 2010-09-23 16:27:35

+0

如果您嘗試使用下劃線,會發生什麼情況? WMI可能錯誤地認爲它們不合法。 – Alnitak 2010-09-23 16:58:28

+0

再次感謝,但仍然沒有運氣。我認爲我是唯一一個嘗試過這樣的人。 – mcass20 2010-09-23 19:14:32

2

我想補充一點在這裏爲那些誰仍然無法得到它的細節...

如果您域名google.com如果記錄是: _finger._tcp.google.com指向目標主機hello.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; 

我已經通過創建示例應用程序並創建區域google.com並設置了SRV記錄及其值,如上所述進行了測試。我希望這對那些聽到其他答覆的人聽起來有點不那麼具有說服力。

+0

更正了一個錯誤。嘗試創建SRV記錄時設置DomainName不正確!要設置TargetHost,必須設置SRVDomainName屬性,該屬性很遺憾沒有記錄在任何地方...... :( – 2011-05-28 12:25:28

相關問題