Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8304729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:55:26+00:00 2026-06-08T17:55:26+00:00

I use a REST-Services which needs Bacis-Authentication on the following way: private void button1_Click(object

  • 0

I use a REST-Services which needs Bacis-Authentication on the following way:

private void button1_Click(object sender, EventArgs e) {
    try {
        var url = "http://172.34.1.111:8088/ustrich/rest/projects/pid/1234";
        using (var wc = this.CreateWebClient(url)) {
            var stopWatch = new Stopwatch();
            stopWatch.Start();
            var s = wc.DownloadString(url);
            stopWatch.Stop();
            this.label1.Text = stopWatch.Elapsed.ToString();
            this.textBox1.Text = s;
        }
    } catch (Exception ex) {
        this.textBox1.Text = ex.ToString();
    }
}

protected WebClient CreateWebClient(string url) {
    var webClient = new WebClient();
    var cache = new CredentialCache { { new Uri(url), "Basic", new NetworkCredential("rest", "rest") } };
    webClient.Credentials = cache;
    webClient.Headers.Add("Content-Type", "text/xml; charset=utf-8");
    webClient.Encoding = Encoding.UTF8;
    return webClient;
}

The problem is now, when I start my Test-Application and execute this code, the first time it takes about 5 seconds on wc.DownloadString(url). The follow calls, when I click the second etc. time on the button, it takes only 300ms.
Now my question: Is there something wrong in my code? Can I optimize something there to resolve the problem that it takes 5 seconds on first call?
Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:55:27+00:00Added an answer on June 8, 2026 at 5:55 pm

    The first time you hit the code, it gets precompiled. It will always be slow this time. I believe you can use MSBUILD to do this when you build your code but that’s just transferring the time to a different part of the process. In production, this will only happen each time the worker process restarts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a REST web service in which I use a ID in the
I'm trying to use this http://www.rcsb.org/pdb/software/rest.do REST services with Qt. I did some get
We have use GWT Platform with GWTP client and rest web services within GUICE
To use flickr as an example, a request URL looks something like this: 'http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key='
I just started to use WCF Rest project template to design a REST service,
I use jersey-client to consume a REST service. I need both the requested Entity
I'm trying to use HTTPWebRequest to access a REST service, and am having problems
I wish to use Spring MVC to provide a REST web service. However, running
Its my first time to use web service in iOS. REST was my first
I understand how to use REST for doing general entity interactions - using urls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.