/// <summary>
        /// Get 方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="serviceSchme">服务名称(http/https)</param>
        /// <param name="serviceName">服务名称</param>
        /// <param name="serviceLink">服务路径</param>
        /// <returns></returns>
        public async Task <T> GetAsync <T>(string serviceSchme, string serviceName, string serviceLink
                                           , Func <T, T> filterFunc = null)
        {
            //获取服务
            IList <ServiceUrl> serviceUrls = await _serviceDiscovery.Discovery(serviceName);

            //负载均衡服务
            ServiceUrl serviceUrl = _loadBalance.Select(serviceUrls);
            //建立请求
            HttpClient          httpClient   = _httpClientFactory.CreateClient("fcdtwin");
            HttpResponseMessage httpResponse = await httpClient.GetAsync(serviceUrl.Url + serviceLink);

            //json转换成对象
            if (httpResponse.StatusCode == HttpStatusCode.OK)
            {
                string json = await httpResponse.Content.ReadAsStringAsync();

                T data = JsonConvert.DeserializeObject <T>(json);
                if (filterFunc != null)
                {
                    data = filterFunc.Invoke(data);
                }
                return(data);
            }
            else
            {
                throw new Exception($"{serviceName}服务调用错误");
            }
        }
Beispiel #2
0
        private async Task <MetaDataInfo> LoadMetaDataHttpAsync()
        {
            string url = ServiceUrl.TrimEnd('/') + "/$metadata";

            using (var client = new WebClient())
            {
                //credintial
                if (!string.IsNullOrEmpty(User))
                {
                    //_token = Convert.ToBase64String(Encoding.ASCII.GetBytes(User + ":" + Password));
                    client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", Token);
                }

                var content = await client.DownloadStringTaskAsync(url);

                if (!string.IsNullOrEmpty(content))
                {
                    content = Helper.PrettyXml(content);
                    GetServiceHttpHeader(client);
                    var metaData = new MetaDataInfo
                    {
                        MetaDataAsString = content,
                        MetaDataVersion  = Helper.GetMetadataVersion(content),
                        ServiceHeader    = GetServiceHttpHeader(client),
                        //ServiceVersion = null,
                        ServiceUrl      = ServiceUrl,
                        SchemaNamespace = "",
                        MediaType       = Media.Http
                    };
                    metaData.ServiceVersion = GetServiceVersion(metaData.ServiceHeader);
                    return(metaData);
                }
                return(new MetaDataInfo());
            }
        }
        /// <summary>
        /// Get方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// param name="ServiceSchme">服务名称:(http/https)</param>
        /// <param name="ServiceName">服务名称</param>
        /// <param name="serviceLink">服务路径</param>
        /// <returns></returns>
        public async Task <T> GetAsync <T>(string Serviceshcme, string ServiceName, string serviceLink)
        {
            // 1、获取服务
            IList <ServiceUrl> serviceUrls = await serviceDiscovery.Discovery(ServiceName);

            // 2、负载均衡服务
            ServiceUrl serviceUrl = loadBalance.Select(serviceUrls);

            // 3、建立请求
            Console.WriteLine($"请求路径:{Serviceshcme} +'://'+{serviceUrl.Url} + {serviceLink}");
            HttpClient httpClient = httpClientFactory.CreateClient("mrico");
            // HttpResponseMessage response = await httpClient.GetAsync(serviceUrl.Url + serviceLink);
            HttpResponseMessage response = await httpClient.GetAsync(Serviceshcme + "://" + serviceUrl.Url + serviceLink);

            // 3.1json转换成对象
            if (response.StatusCode == HttpStatusCode.OK)
            {
                string json = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <T>(json));
            }
            else
            {
                // 3.2、进行自定义异常处理,这个地方进行了降级处理
                throw new Exception($"{ServiceName}服务调用错误:{response.Content.ReadAsStringAsync()}");
            }
        }
        /// <summary>
        /// Post方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// param name="ServiceSchme">服务名称:(http/https)</param>
        /// <param name="ServiceName">服务名称</param>
        /// <param name="serviceLink">服务路径</param>
        /// <param name="paramData">服务参数</param>
        /// <returns></returns>
        public T Post <T>(string serviceshcme, string serviceName, string serviceLink, object paramData = null)
        {
            // 1、获取服务
            IList <ServiceUrl> serviceUrls = serviceDiscovery.Discovery(serviceName).Result;

            // 2、负载均衡服务
            ServiceUrl serviceUrl = loadBalance.Select(serviceUrls);

            // 3、建立请求
            Console.WriteLine($"请求路径:{serviceshcme} +'://'+{serviceUrl.Url} + {serviceLink}");

            // 3.1 转换成json内容
            HttpContent hc = new StringContent(JsonConvert.SerializeObject(paramData), Encoding.UTF8, "application/json");

            // HttpResponseMessage response = await httpClient.GetAsync(serviceUrl.Url + serviceLink);
            HttpResponseMessage response = httpClient.PostAsync(serviceshcme + "://" + serviceUrl.Url + serviceLink, hc).Result;

            // 3.1json转换成对象
            if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
            {
                string json = response.Content.ReadAsStringAsync().Result;

                return(JsonConvert.DeserializeObject <T>(json));
            }
            else
            {
                // 3.2、进行自定义异常处理,这个地方进行了降级处理
                throw new Exception($"{serviceName}服务调用错误:{response.Content.ReadAsStringAsync()}");
            }
        }
        private async Task <ServiceUrl> CreateNewServiceUrlAsync(string serviceUrlAddress, string channelId, string conversationId)
        {
            ServiceUrl serviceUrl = await UnitOfWork
                                    .ServiceUrls
                                    .AddAsync(new ServiceUrl
            {
                Address = serviceUrlAddress
            });

            // If there are messages from the same conversation, update their service URLs.
            IList <ScheduledMessageDetails> detailsFromSameConversation =
                await UnitOfWork.ScheduledMessageDetails.GetScheduledMessageDetailsAsync(
                    channelId,
                    conversationId,
                    false);

            foreach (ScheduledMessageDetails messageDetails in detailsFromSameConversation)
            {
                messageDetails
                .DetailsServiceUrls
                .Add(new ScheduledMessageDetailsServiceUrl
                {
                    Details    = messageDetails,
                    ServiceUrl = serviceUrl
                });
            }

            return(serviceUrl);
        }
        private async Task <ServiceUrl> UpdateExistingServiceUrlAsync(ServiceUrl serviceUrl, string channelId, string conversationId)
        {
            // If there are messages from the same conversation, update their service URLs.
            IList <ScheduledMessageDetails> detailsFromSameConversation =
                await UnitOfWork.ScheduledMessageDetails.GetScheduledMessageDetailsAsync(
                    channelId,
                    conversationId,
                    true);

            foreach (ScheduledMessageDetails messageDetails in detailsFromSameConversation)
            {
                ScheduledMessageDetailsServiceUrl lastDetailsServiceUrl = messageDetails
                                                                          .DetailsServiceUrls
                                                                          .OrderByDescending(detailsServiceUrl => detailsServiceUrl.CreatedOn)
                                                                          .First();

                if (lastDetailsServiceUrl.ServiceUrl != serviceUrl)
                {
                    messageDetails
                    .DetailsServiceUrls
                    .Add(new ScheduledMessageDetailsServiceUrl
                    {
                        Details    = messageDetails,
                        ServiceUrl = serviceUrl
                    });
                }
            }

            return(serviceUrl);
        }
        private async Task <ScheduledMessageDetails> CreateMessageDetailsAsync(Activity activity)
        {
            ScheduledMessageDetails scheduledMessageDetails = new ScheduledMessageDetails
            {
                FromId         = activity.Recipient.Id,
                FromName       = activity.Recipient.Name,
                RecipientId    = activity.From.Id,
                RecipientName  = activity.From.Name,
                ChannelId      = activity.ChannelId,
                ConversationId = activity.Conversation.Id,
                Locale         = activity.Locale,
                TimeZoneOffset = activity.LocalTimestamp?.Offset
            };

            ServiceUrl serviceUrl = await GetOrCreateServiceUrlAsync(activity);

            scheduledMessageDetails.DetailsServiceUrls = new List <ScheduledMessageDetailsServiceUrl>
            {
                new ScheduledMessageDetailsServiceUrl
                {
                    Details    = scheduledMessageDetails,
                    ServiceUrl = serviceUrl
                }
            };

            return(scheduledMessageDetails);
        }
        private void GenerateSuggestedServiceUrl()
        {
            var serviceUrl = ServiceUrl == null ? null : ServiceUrl.Trim();

            if (string.IsNullOrWhiteSpace(serviceUrl))
            {
                SuggestedServiceUrl = null;
            }
            else
            {
                // No need to suggest any more
                if (serviceUrl.EndsWith(DYNAMICS_COM) || serviceUrl.EndsWith(CRMLIVETIE_COM) || serviceUrl.EndsWith(DYNAMICSINT_COM))
                {
                    SuggestedServiceUrl = null;
                }
                else
                {
                    bool isDone = false;

                    isDone = TryGenerateSuggestedServiceUrlWithPostfix(serviceUrl, DEFAULT_SERVICE_URL_POSTFIX) ||
                             TryGenerateSuggestedServiceUrlWithPostfix(serviceUrl, DYNAMICS_COM) ||
                             TryGenerateSuggestedServiceUrlWithPostfix(serviceUrl, CRMLIVETIE_COM) ||
                             TryGenerateSuggestedServiceUrlWithPostfix(serviceUrl, DYNAMICSINT_COM);

                    if (!isDone)
                    {
                        SuggestedServiceUrl = serviceUrl + DEFAULT_SERVICE_URL_POSTFIX;
                    }
                }
            }
        }
        private async Task <ServiceUrl> GetOrCreateServiceUrlAsync(Activity activity)
        {
            ServiceUrl serviceUrl = await UnitOfWork.ServiceUrls.GetByAddressAsync(activity.ServiceUrl);

            return(serviceUrl == null
                                ? await CreateNewServiceUrlAsync(activity.ServiceUrl, activity.ChannelId, activity.Conversation.Id)
                                : await UpdateExistingServiceUrlAsync(serviceUrl, activity.ChannelId, activity.Conversation.Id));
        }
        private ProtocolContext InitContext(string applicationToken, string servicePubKey, string clientPrivKey, string serviceSubdomain)
        {
            var serializer = new HttpBodySerializer();
            var serviceUrl = ServiceUrl.ProvideByToken(applicationToken).Replace("api", serviceSubdomain);
            var client     = new PheHttpClient(serializer, applicationToken, serviceUrl);
            var context    = new ProtocolContext(applicationToken, client, servicePubKey, clientPrivKey);

            return(context);
        }
Beispiel #11
0
        private string AnalyzeUri(MethodInfo targetMethod)
        {
            if (string.IsNullOrWhiteSpace(ServiceUrl))
            {
                throw new ArgumentNullException("ServiceUrl");
            }
            var fullName = targetMethod.DeclaringType.FullName.Replace('.', '-') + ('-') + targetMethod.Name;

            return(ServiceUrl.TrimEnd('/') + '/' + fullName);
        }
Beispiel #12
0
        public async Task <IActionResult> Export(int?id)
        {
            HttpClient client = new HttpClient();
            ServiceUrl urls   = Config.Value;

            client.BaseAddress = new Uri(urls.FileGenerationServiceUrl);
            string apiUrl = "api/pahFileGeneration/GenerateFile/" + id.ToString();
            await client.GetAsync(apiUrl);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Load(int?id)
        {
            HttpClient client = new HttpClient();
            ServiceUrl urls   = _config.Value;

            client.BaseAddress = new Uri(urls.ResponseLoadServiceUrl);
            string apiUrl = "api/PahResponseLoad/ResponseLoad/" + id.ToString();
            await client.GetAsync(apiUrl);

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #14
0
        internal override void Validate()
        {
            base.Validate();

            if ((string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(Password)) && string.IsNullOrWhiteSpace(ApiKey))
            {
                throw new ConfigurationException("Login Credentials or an API Key is required.");
            }

            if ((!string.IsNullOrWhiteSpace(Username) || !string.IsNullOrWhiteSpace(Password)) && !string.IsNullOrWhiteSpace(ApiKey))
            {
                throw new ConfigurationException("Cannot provide both Login Credentials and an API key.");
            }

            if (string.IsNullOrWhiteSpace(ApiKey))
            {
                if (string.IsNullOrEmpty(Username))
                {
                    throw new ConfigurationException("UserName is missing.");
                }

                if (Username.Trim().Length > 50)
                {
                    throw new ConfigurationException("UserName must be 50 characters or less.");
                }

                if (string.IsNullOrEmpty(Password))
                {
                    throw new ConfigurationException("Password is missing.");
                }

                if (Password.Trim().Length > 50)
                {
                    throw new ConfigurationException("Password must be 50 characters or less.");
                }
            }

            if (string.IsNullOrWhiteSpace(MerchantName))
            {
                throw new ConfigurationException("MerchantName is required");
            }

            #region Validate endpoint

            if (ServiceUrl != ServiceEndpoints.BILLPAY_CERTIFICATION &&
                ServiceUrl != ServiceEndpoints.BILLPAY_PRODUCTION &&
                ServiceUrl != ServiceEndpoints.BILLPAY_TEST &&
                !ServiceUrl.Contains("localhost"))
            {
                throw new ConfigurationException("Please use one of the pre-defined BillPay service urls.");
            }

            #endregion
        }
 public virtual void Accept()
 {
     StartWorkInProgress();
     ServiceUrl     = ServiceUrl.Trim();
     IsAddressValid = IsValidUrl(ServiceUrl);
     if (IsAddressValid)
     {
         StoreConnectionAddress();
         TryClose(true);
     }
     StopWorkInProgress();
 }
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = ServiceUrl != null?ServiceUrl.GetHashCode() : 0;

                hashCode = (hashCode * 397) ^ (ChannelId != null ? ChannelId.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (ConversationId != null ? ConversationId.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (BotId != null ? BotId.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (UserId != null ? UserId.GetHashCode() : 0);
                return(hashCode);
            }
        }
Beispiel #17
0
        public string[] GetSponsorIds(string registrationId, string promoCode)
        {
            string[] result = new string[] { };
            try
            {
                using (var client = new HttpClient())
                {
                    var url  = new Uri($"{ ServiceUrl.GetUrl() }{ServiceUrl.GetSponsorIdsUrl}/{registrationId}/{promoCode}");
                    var json = client.GetStringAsync(url).Result;
                    result = JsonConvert.DeserializeObject <string[]>(json);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(result);
        }
Beispiel #18
0
        public ImageResponse IsRegistrationKeyValid(string registrationID, string promoCode)
        {
            var result = new ImageResponse();

            try
            {
                using (var client = new HttpClient())
                {
                    var url  = new Uri($"{ ServiceUrl.GetUrl() }{ServiceUrl.RegistrationdKeyUrl}/{registrationID}/{promoCode}");
                    var json = client.GetStringAsync(url).Result;
                    result = JsonConvert.DeserializeObject <ImageResponse>(json);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(result);
        }
Beispiel #19
0
        public string GetMessageText(string registrationId, string promoCode)
        {
            var result = string.Empty;

            try
            {
                using (var client = new HttpClient())
                {
                    var url  = new Uri($"{ ServiceUrl.GetUrl() }{ServiceUrl.MessageTextUrl}/{registrationId}/{promoCode}");
                    var json = client.GetStringAsync(url).Result;
                    result = JsonConvert.DeserializeObject <string>(json);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(result);
        }
Beispiel #20
0
        public bool IsValidPromoCode(string promoCode)
        {
            var result = false;

            try
            {
                using (var client = new HttpClient())
                {
                    var url  = new Uri($"{ ServiceUrl.GetUrl() }{ServiceUrl.IsPromoCodeValidUrl}/{ promoCode }");
                    var json = client.GetStringAsync(url).Result;
                    result = JsonConvert.DeserializeObject <bool>(json);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(result);
        }
Beispiel #21
0
        public SplashDefinition AgentSplashDefData(string registrationId, string promoCode)
        {
            var result = default(SplashDefinition);

            try
            {
                using (var client = new HttpClient())
                {
                    var url  = new Uri($"{ ServiceUrl.GetUrl() }{ServiceUrl.AgentSplashDefDataUrl}/{registrationId}/{promoCode}");
                    var json = client.GetStringAsync(url).Result;
                    result = JsonConvert.DeserializeObject <SplashDefinition>(json);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(result);
        }
Beispiel #22
0
        public string HO_4_0_0()
        {
            var result = string.Empty;

            try
            {
                using (var client = new HttpClient())
                {
                    var url  = new Uri($"{ ServiceUrl.GetUrl() }{ServiceUrl.HO4VersionUrl}");
                    var json = client.GetStringAsync(url).Result;
                    result = JsonConvert.DeserializeObject <string>(json);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(result);
        }
Beispiel #23
0
        public virtual async Task Accept()
        {
            certValidationFailed = false;
            StartWorkInProgress();
            ServiceUrl = ServiceUrl.Trim();
            var isValidUrl = await IsValidUrl(ServiceUrl);

            ShowError = !isValidUrl;

            if (!ShowError)
            {
                StoreConnectionAddress();
                TryClose(true);
            }
            else
            {
                ErrorMessage = certValidationFailed ? CertValidationErrorMessage : ConnectionErrorMessage;
            }

            StopWorkInProgress();
        }
        private ElasticClient GetCloudSearchClient()
        {
            string IndexName          = string.Empty;
            string ElasticInstanceUri = string.Empty;

            if (!string.IsNullOrEmpty(ServiceUrl))
            {
                IndexName          = ServiceUrl.Split('/').Last();
                ElasticInstanceUri = ServiceUrl.Substring(0, ServiceUrl.LastIndexOf("/"));
            }

            Uri node = new Uri(ElasticInstanceUri);
            ConnectionSettings settings = new ConnectionSettings(node);

            if (UserId != null && Password != null)
            {
                settings.BasicAuthentication(UserId, Password);
            }
            settings.DefaultIndex(IndexName);
            return(new ElasticClient(settings));
        }
Beispiel #25
0
        public RegistrationResponse MemberRegistration(RegistrationRequest request)
        {
            var result = new RegistrationResponse();

            try
            {
                using (var client = new HttpClient())
                {
                    var url      = new Uri($"{ ServiceUrl.GetUrl() }{ServiceUrl.MemberRegistrationUrl}");
                    var content  = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
                    var response = client.PostAsync(url, content);
                    var r        = response.Result.Content.ReadAsStringAsync().Result;
                    result = JsonConvert.DeserializeObject <RegistrationResponse>(r);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(result);
        }
        /// <summary>
        /// Create the context with passw0rd's application credentials.
        /// How to get passw0rd's application credentials
        /// you will find <see href="https://github.com/passw0rd/cli">here</see>.
        /// </summary>
        /// <returns>The new instance of the <see cref="ProtocolContext"/>
        ///  which contains application credentials.</returns>
        /// <param name="appToken">Application token.</param>
        /// <param name="servicePublicKey">Service public key.</param>
        /// <param name="appSecretKey">Application Secret Key.</param>
        /// <param name="updateToken">Update token.
        /// How to generate Update Token you will find
        /// <see href="https://github.com/passw0rd/cli#get-an-update-token">here</see>.</param>
        public static ProtocolContext Create(
            string appToken,
            string servicePublicKey,
            string appSecretKey,
            string updateToken = null)
        {
            Validation.NotNullOrWhiteSpace(appToken, "Application token isn't provided.");
            Validation.NotNullOrWhiteSpace(servicePublicKey, "Service Public Key isn't provided.");
            Validation.NotNullOrWhiteSpace(appSecretKey, "Application Secret Key isn't provided.");

            var serializer = new HttpBodySerializer();

            var client = new PheHttpClient(serializer, appToken, ServiceUrl.ProvideByToken(appToken));

            var ctx = new ProtocolContext(appToken, client, servicePublicKey, appSecretKey);

            if (!string.IsNullOrWhiteSpace(updateToken))
            {
                ctx.UpdatePheClients(updateToken);
            }

            return(ctx);
        }
Beispiel #27
0
        /// <summary>
        /// Get方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// param name="ServiceSchme">服务名称:(http/https)</param>
        /// <param name="ServiceName">服务名称</param>
        /// <param name="serviceLink">服务路径</param>
        /// <returns></returns>
        public async Task <T> GetAsync <T>(string Serviceshcme, string ServiceName, string serviceLink)
        {
            // 1、获取服务
            IList <ServiceUrl> serviceUrls = await serviceDiscovery.Discovery(ServiceName);

            // 2、负载均衡服务
            ServiceUrl serviceUrl = loadBalance.Select(serviceUrls);

            // 3、建立请求
            HttpClient          httpClient = httpClientFactory.CreateClient("consul");
            HttpResponseMessage response   = await httpClient.GetAsync(serviceUrl.Url + serviceLink);

            // 3.1json转换成对象
            if (response.StatusCode == HttpStatusCode.OK)
            {
                string json = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <T>(json));
            }
            else
            {
                throw new Exception($"{ServiceName}服务调用错误");
            }
        }
        public async Task <IList <Team> > GetTeams()
        {
            // 1、获取服务
            IList <ServiceUrl> serviceUrls = await serviceDiscovery.Discovery(ServiceName);

            // 2、负载均衡服务
            ServiceUrl serviceUrl = loadBalance.Select(serviceUrls);

            // 3、建立请求
            HttpClient          httpClient = httpClientFactory.CreateClient();
            HttpResponseMessage response   = await httpClient.GetAsync(serviceUrl.Url + serviceLink);

            // 3.1json转换成对象
            IList <Team> teams = null;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                string json = await response.Content.ReadAsStringAsync();

                teams = JsonConvert.DeserializeObject <List <Team> >(json);
            }

            return(teams);
        }
        protected override void Execute(CodeActivityContext context)
        {
            var serviceUrl  = ServiceUrl.Get(context);
            var apiKey      = ApiKey.Get(context);
            var versionDate = VersionDate.Get(context);

            var authenticator = new IamAuthenticator(apikey: apiKey);
            var service       = new AssistantService(versionDate, authenticator);

            service.SetServiceUrl(serviceUrl);

            var assistantId = AssistantId.Get(context);
            var text        = Text.Get(context);

            // SuggestedIntentの取得
            var suggestedIntent = FetchSuggestedIntent(assistantId, text, service);

            SuggestedIntent.Set(context, suggestedIntent);

            // Confidenciesの取得
            var confidencies = FetchIntentConfidencies(assistantId, text, service);

            Confidencies.Set(context, confidencies);
        }
Beispiel #30
0
        protected override void MapUriRequested(HttpMapTileDataSource sender, MapTileUriRequestedEventArgs args)
        {
            var deferral = args.Request.GetDeferral();

            if (!(args.ZoomLevel < 4 && Epsg == 4326))
            {
                var extent      = GetTileExtent(args.X, args.Y, args.ZoomLevel);
                var urlTemplate = string.Concat(ServiceUrl,
                                                ServiceUrl.EndsWith("?")
            ? string.Empty
            : ServiceUrl.EndsWith("&") ? string.Empty : (ServiceUrl.Contains("?") ? "&" : "?"), WmsPostFix);
                var url = string.Format(CultureInfo.InvariantCulture,
                                        urlTemplate, extent.XLow, extent.YLow, extent.XHigh, extent.YHigh, TileSize, Epsg,
                                        string.Join(",", Layers),
                                        Version, ReferenceSystemName, ImageType);

#if DEBUG
                Debug.WriteLine("Tile x={0}, y={1}, zoom={2}", args.X, args.Y, args.ZoomLevel);
                Debug.WriteLine("adding uri {0}", url);
#endif
                args.Request.Uri = new Uri(url);
            }
            deferral.Complete();
        }