Get .svc file info of IIS web service on remote computer

て烟熏妆下的殇ゞ 提交于 2020-01-06 08:22:46

问题


i've written a code to retrieve list of IIS services on a remote computer, now I am trying to retrieve information about the .svc file of the web service. The code below works for all the services that are stored in the inetpub folder, but i know it is not necessary to store the services there and it can be saved anywhere.

public static void IISWebSvcLister(string Hos)
    {
        try
        {
            string s = null;
            Hos = Hos.Trim();
            DirectoryEntry w3svc = new DirectoryEntry("IIS://" + Hos + "/w3svc/1/root");

            foreach (DirectoryEntry de in w3svc.Children)
            {
                if (de.Children.ToString() != null)
                {
                    s += de.Name.ToString() + "\n";
                    //string sp = HttpContext.Current.Server.MapPath(@"~\\"+Hos+"\c$\inetpub\wwwroot\");

                    try
                    {
                        string[] filePaths = Directory.GetFiles(@"\\" + Hos + @"\c$\inetpub\wwwroot\" + de.Name.ToString(), "*.svc", SearchOption.AllDirectories);

                        for (int i = 0; i < filePaths.Length; i++)
                        {
                            FileInfo fi = new FileInfo(filePaths[i]);
                            Console.Write(fi.CreationTime.ToString() + "\t" + fi.Length.ToString());
                            string[] k = filePaths[i].Split('\\');
                            filePaths[i] = k[k.Length-2]+"\\"+k[k.Length - 1];
                            Console.WriteLine("\t" + filePaths[i]);
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine(de.Name.ToString());
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

How do i get the files for the services not stored in c:\inetpub\wwwroot ?

Thanks

来源:https://stackoverflow.com/questions/6491198/get-svc-file-info-of-iis-web-service-on-remote-computer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!