Ejemplo n.º 1
0
        private static String FormUrl(IService service)
        {
            ServiceDescriptor serviceDescriptor = service.GetServiceDescriptor();

            String requestName = service.GetRequest();

            Connect.Model.ServiceDescriptor.Request request = serviceDescriptor.GetRequest(requestName);

            String protocol = serviceDescriptor.GetProtocol();

            String instance = serviceDescriptor.GetInstance();
            String port     = serviceDescriptor.GetPort();

            String context = serviceDescriptor.GetContext();
            String apiPath = request.GetApi();

            StringBuilder url = new StringBuilder();

            if (protocol != null)
            {
                if (protocol.Equals(Constants.SERVICE_DESCRIPTOR_HTTP_PROTOCOL, StringComparison.OrdinalIgnoreCase))
                {
                    url.Append(Constants.CONNECTION_HTTP);
                }
                else if (protocol.Equals(Constants.SERVICE_DESCRIPTOR_HTTPS_PROTOCOL, StringComparison.OrdinalIgnoreCase))
                {
                    url.Append(Constants.CONNECTION_HTTPS);
                }

                url.Append("://");
            }

            url.Append(instance);

            if (port != null && port.Length > 0)
            {
                url.Append(":" + port);
            }

            if (context != null && context.Length > 0)
            {
                url.Append("/" + context);
            }

            if (apiPath != null && apiPath.Length > 0)
            {
                url.Append("/" + apiPath);
            }

            return(url.ToString());
        }