简体   繁体   中英

Is it possible to take asp.net web adress from IIS

I want to read web services information especially adress from iis. For IIS7 I can read following information with this code.

var iisManager = new ServerManager();
sites = iisManager.Sites;

foreach (var site in sites)

{
  IISService serv = new IISService();

  serv.Name = site.Name;
  serv.State= site.State.ToString();
  serv.PhysicalPath= site.Applications["/"].VirtualDirectories[0].PhysicalPath;

allServices.Add(serv);

}

For II6

DirectoryEntry IIsEntities = new DirectoryEntry(Path);

foreach (DirectoryEntry IIsEntity in IIsEntities.Children)
{
    if (IIsEntity.SchemaClassName == "IIsWebServer")
    {
        yield return new Website
        (
            IIsEntity.Properties["ServerComment"].Value.ToString(),
            GetPath(IIsEntity),
            (ServerState)IIsEntity.Properties["ServerState"].Value

        );
    }
}

I can read above information but I want to read end point information of asmx web service. Thats like : http://localhost:8091/Service1.asmx

Is it possible read port number or name of asmx file ?

Nope. IIS has nothing to do with it. IIS only concerns about hosting-related operations and serving requests. If you are talking about services, you might want to look at making your services discoverable, exposing metadata and WSDL. However, this will not expose any file or any "internals" of the service...just the interface (public facing details)...for example if you have a RESTful service, the physical files behind it will not be exposed.

I ask IIS for local adresses so I can succeded to get enough information to form asmx local web adress.

foreach (var site in sites)
{
  IISService serv = new IISService();

  serv.Name = site.Name;
  serv.State= site.State.ToString();
  serv.PhysicalPath= site.Applications["/"].VirtualDirectories[0].PhysicalPath;

  System.Net.IPEndPoint endP = site.Bindings[0].EndPoint;

  string protocol =   site.Bindings[0].Protocol;

  allServices.Add(serv);
}

I can get Binding information with this solution(port and Protocol). I can find Service1.asmx file when I ask for *.asmx with Directory.GetFiles in PhysicalPath. So I get needed information to construct web services adress.

//What I need http://localhost:8091/Service1.asmx

string adress = protocol + "://localhost:" + endP.Port + "/" + " *.asmx file from PhysicalPath";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM