Exemple #1
0
        public static ApplicationDescriptionCollection  getServersDescr(string aDiscoveryUrl)
        {
            Uri lDiscoveryUrl;

            if (String.IsNullOrWhiteSpace(aDiscoveryUrl))
            {
                lDiscoveryUrl = new Uri("opc.tcp://localhost:4840");
            }
            else
            {
                lDiscoveryUrl = new Uri(aDiscoveryUrl);
            }

            var lAllServers = DiscoveryClient.Create(lDiscoveryUrl).FindServers(null);
            var lResult     = new ApplicationDescriptionCollection();

            foreach (var lServer in lAllServers)
            {
                if (lServer.ApplicationType == ApplicationType.ClientAndServer || lServer.ApplicationType == ApplicationType.Server)
                {
                    lResult.Add(lServer);
                }
            }

            return(lResult);
        }
Exemple #2
0
        /// <summary>
        /// 发现服务(由客户端请求)
        /// </summary>
        /// <param name="requestHeader"></param>
        /// <param name="endpointUrl"></param>
        /// <param name="localeIds"></param>
        /// <param name="serverUris"></param>
        /// <param name="servers"></param>
        /// <returns></returns>
        public override ResponseHeader FindServers(
            RequestHeader requestHeader,
            string endpointUrl,
            StringCollection localeIds,
            StringCollection serverUris,
            out ApplicationDescriptionCollection servers)
        {
            servers = new ApplicationDescriptionCollection();

            ValidateRequest(requestHeader);

            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":请求查找服务...");
            string hostName = Dns.GetHostName();

            lock (_serverTable)
            {
                foreach (var item in _serverTable)
                {
                    StringCollection urls = new StringCollection();
                    foreach (var url in item.DiscoveryUrls)
                    {
                        if (url.Contains("localhost"))
                        {
                            string str = url.Replace("localhost", hostName);
                            urls.Add(str);
                        }
                        else
                        {
                            urls.Add(url);
                        }
                    }

                    servers.Add(new ApplicationDescription()
                    {
                        ApplicationName     = item.ServerNames.FirstOrDefault(),
                        ApplicationType     = item.ServerType,
                        ApplicationUri      = item.ServerUri,
                        DiscoveryProfileUri = item.SemaphoreFilePath,
                        DiscoveryUrls       = urls,
                        ProductUri          = item.ProductUri,
                        GatewayServerUri    = item.GatewayServerUri
                    });
                }
            }

            return(CreateResponse(requestHeader, StatusCodes.Good));
        }