예제 #1
0
        public static IEnumerable<ServiceInstanceInfo> GetServiceInstances()
        {
            var serviceInstances = new List<ServiceInstanceInfo>();
            var tcpPort = GetPortForProtocol("net.tcp");
            var httpPort = GetPortForProtocol("http");
            var httpsPort = GetPortForProtocol("https");

            using (ServerManager serverManager = new ServerManager())
            {
                var site = serverManager.Sites.FirstOrDefault(s => s.Name == WebApplicationName);

                foreach (var app in site.Applications.Where(a => a.Path != "/" && a.VirtualDirectories.Count > 0))
                {
                    var servicesName = app.Path.TrimStart('/');
                    var physicalPath = app.VirtualDirectories[0].PhysicalPath;

                    var serviceInstanceInfo = new ServiceInstanceInfo()
                    {
                        ServicesName = servicesName,
                        ServicesHost = Environment.MachineName.ToLowerInvariant(),
                        PhysicalPath = physicalPath,
                        ProductVersion = BusinessServiceConfiguration.GetProductVersion(physicalPath),
                        TcpPort = tcpPort,
                        HttpPort = httpPort,
                        HttpsPort = httpsPort
                    };

                    serviceInstances.Add(serviceInstanceInfo);
                }
            }

            return serviceInstances;
        }
        public string CreateAdminHomeUrl(ServiceInstanceInfo serviceInstance)
        {
            var port = (serviceInstance.HttpsPort > -1) ? serviceInstance.HttpsPort.ToString() : ((serviceInstance.HttpPort > -1) ? serviceInstance.HttpPort.ToString() : "80");
            var protocol = (serviceInstance.HttpsPort > -1) ? "https" : "http";
            var host = HttpContext.Current != null ? HttpContext.Current.Request.Url.Host : serviceInstance.ServicesHost;
            var url = protocol + "://" + host + ":" + port + "/" + serviceInstance.ServicesName + "/admin";

            return url;
        }