private DescribeEndpointResponse getEndpointResponse(String data, String endpointType)
        {
            IReader             reader  = ReaderFactory.CreateInstance(FormatType.JSON);
            UnmarshallerContext context = new UnmarshallerContext();

            context.ResponseDictionary = reader.Read(data, "DescribeEndpointsResponse");

            int endpointsLength = context.Length("DescribeEndpointsResponse.Endpoints.Length");

            for (int i = 0; i < endpointsLength; i++)
            {
                if (endpointType.Equals(context
                                        .StringValue("DescribeEndpointsResponse.Endpoints[" + i + "].Type")))
                {
                    DescribeEndpointResponse response = new DescribeEndpointResponse();

                    response.RequestId = context.StringValue("DescribeEndpointsResponse.RequestId");
                    response.Product   = context.StringValue("DescribeEndpointsResponse.Endpoints[" + i + "].SerivceCode");
                    response.Endpoint  = context.StringValue("DescribeEndpointsResponse.Endpoints[" + i + "].Endpoint");
                    response.RegionId  = context.StringValue("DescribeEndpointsResponse.Endpoints[" + i + "].Id");
                    return(response);
                }
            }
            return(null);
        }
        public Endpoint GetEndpoint(String regionId, String product, String locationProduct,
                                    Credential credential, LocationConfig locationConfig)
        {
            if (null == locationProduct)
            {
                return(null);
            }
            Endpoint endpoint = null;

            DescribeEndpointResponse response = describeEndpointService.DescribeEndpoint(regionId, locationProduct,
                                                                                         credential, locationConfig);

            if (null == response)
            {
                return(endpoint);
            }

            ISet <string> regionIds = new HashSet <String>();

            regionIds.Add(regionId);

            List <ProductDomain> productDomainList = new List <ProductDomain>();

            productDomainList.Add(new ProductDomain(product, response.Endpoint));
            endpoint = new Endpoint(response.RegionId, regionIds, productDomainList);
            return(endpoint);
        }
        public DescribeEndpointResponse DescribeEndpoint(String regionId, String locationProduct,
                                                         Credential credential, LocationConfig locationConfig)
        {
            if (isEmpty(locationProduct))
            {
                return(null);
            }

            DescribeEndpointRequest request = new DescribeEndpointRequest();

            request.AcceptFormat    = FormatType.JSON;
            request.Id              = regionId;
            request.RegionId        = locationConfig.RegionId;
            request.LocationProduct = locationProduct;
            request.EndpointType    = DEFAULT_ENDPOINT_TYPE;

            ProductDomain domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            try
            {
                HttpRequest  httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
                HttpResponse httpResponse = HttpResponse.GetResponse(httpRequest);
                if (httpResponse.isSuccess())
                {
                    String data = System.Text.Encoding.UTF8.GetString(httpResponse.Content);
                    DescribeEndpointResponse response = getEndpointResponse(data, DEFAULT_ENDPOINT_TYPE);
                    if (null == response || isEmpty(response.Endpoint))
                    {
                        return(null);
                    }
                    return(response);
                }
                AcsError error = readError(httpResponse, FormatType.JSON);
                if (500 <= httpResponse.Status)
                {
                    Console.WriteLine("Invoke_Error, requestId:" + error.RequestId + "; code:" + error.ErrorCode
                                      + "; Msg" + error.ErrorMessage);
                    return(null);
                }
                Console.WriteLine("Invoke_Error, requestId:" + error.RequestId + "; code:" + error.ErrorCode
                                  + "; Msg" + error.ErrorMessage);
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invoke Remote Error,Msg" + e.Message);
                return(null);
            }
        }