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 7685759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:19:30+00:00 2026-05-31T19:19:30+00:00

I need to call 3 WCF services as below, var client = new WebClient();

  • 0

I need to call 3 WCF services as below,

var client = new WebClient();
    client.Headers[HttpRequestHeader.ContentType] = "application/json";
    var resultJson1 = client.UploadString("http://localhost:45868/Product/GetAvailableProductsByContact",
                                         jsonser1);
var resultJson2= client.UploadString("http://localhost:45868/Product/GetMemberProductsByContact",
                                         jsonser2);

var resultJson3= client.UploadString("http://localhost:45868/Product/GetCoachProductsByContact",
                                         jsonser3);

This takes a lot of time to get results and display on the page. Can anyone help me how I could execute them in parallel?

  • 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-05-31T19:19:31+00:00Added an answer on May 31, 2026 at 7:19 pm

    You can use the task parallelism library:

    Task<string>[] taskArray = new Task<string>[]
        {
            Task.Factory.StartNew(() => {
                var client = new WebClient();
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                var json = client.UploadString("http://localhost:45868/Product/GetAvailableProductsByContact",
                                         jsonser1);
                return json;
            }),
            Task.Factory.StartNew(() => {
                var client = new WebClient();
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                var json = client.UploadString("http://localhost:45868/Product/GetMemberProductsByContact",
                                         jsonser2);
                return json;
            }),
            Task.Factory.StartNew(() => {
                var client = new WebClient();
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                var json = client.UploadString("http://localhost:45868/Product/GetCoachProductsByContact",
                                         jsonser3);
                return json;
            }),
        };
    
    // the request for .Result is blocking and waits until each task
    // is completed before continuing; however, they should also all
    // run in parallel instead of sequentially.
    var resultJson1 = taskArray[0].Result;
    var resultJson2 = taskArray[1].Result;
    var resultJson3 = taskArray[2].Result;
    

    Or alternatively, since your requests are all very similar, differing only by the url and upload string, you can use LINQ AsParallel array processing:

    var requests = new [] {
        new { Url = "http://localhost:45868/Product/GetAvailableProductsByContact", Input = jsonser1 },
        new { Url = "http://localhost:45868/Product/GetMemberProductsByContact", Input = jsonser2 },
        new { Url = "http://localhost:45868/Product/GetCoachProductsByContact", Input = jsonser3 },
    };
    var result = requests.AsParallel().Select(req => {
        var client = new WebClient();
        client.Headers[HttpRequestHeader.ContentType] = "application/json";
        var json = client.UploadString(req.Url, req.Input);
        return json;
    }).ToArray();
    
    // when above code has finished running, all tasks are completed
    var resultJson1 = result[0];
    var resultJson2 = result[1];
    var resultJson3 = result[2];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call some PL/SQL procedures from my Java application. I can do
We have a couple of WCF services hosted in an asp.net application on IIS.
I am moving my WSE3 web services to the WCF. But the client is
I have a Windows Service Application in which i create WCF services in it.
I am trying to call WCF 4 Http Web Services which are hosted within
On a scheduled interval I need to call a WCF service call another WCF
I need to protect my WCF web services and was thinking what is the
I need to create a project for multiple web services using WCF in c#.
A Silverlight 3.0 application tries to call WCF service but the application can not
Need to call a filter function on some options based on a radio selected

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.