Search code examples
c#web-serviceswcfhttprequestwebservice-client

Need to Run multiple HTTP Web Request in Parallel to a Web Service through another Web Service


I Need to Run multiple HTTP Web Request in Parallel to a Web Service through another Web Service.

I have found a Related Relevant Solution Here : Trying to run multiple HTTP requests in parallel, but being limited by Windows (registry) Trying to run multiple HTTP requests in parallel, but being limited by Windows (registry)

My problem is similar to this problem.

Earlier , I was calling a Web Service multiple times in parallel from my machine via a C# WinForms Application. At that time , using the ServicePointManager.DefaultConnectionLimit solved my problem.

Now , my requirement has changed. There is another application, which is now a Web Service with just 1 webpage , that is called by multiple users in parallel. This Web Service calls the other Web Service , so we have multiple parallel calls going out of a Web Server machine.

I'm a noob in Web , so I cant figure out where i need to set the ServicePointManager.DefaultConnectionLimit on the Web Service. (I was doing it in the Main() in my Winforms App.)

My problem is where do I specify the ServicePointManager.DefaultConnectionLimit ??

The Web Service doesn't have a Main() , it only has a Global.asax which mostly has code snippets and plumbing.

    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    public Global()
    {
        InitializeComponent();
    }   

    protected void Application_Start(Object sender, EventArgs e)
    { 
        AppDomain.CurrentDomain.UnhandledException +=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

        this.Initialise();
    }

    #region Web Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
        // 
        // Global
        // 
        this.Error += new System.EventHandler(this.Global_Error);

    }
    #endregion

    private void Global_Error(object sender, System.EventArgs e)
    {
        HandleLastError();
    }


    protected void Application_Error(Object sender, EventArgs e)
    {
        HandleLastError();
    }

    private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        Exception unhandledException = (Exception)e.ExceptionObject;
        HandleException(unhandledException);
    }

    private void HandleLastError()
    {
        Exception lastError = Server.GetLastError();

        HandleException(lastError);
    }

    private static void HandleException(Exception exception)
    {
        Logger logger = new Logger(typeof(CreditCheck));

        string lastErrorMessage = (exception == null ? "No exception" : exception.Message);

        logger.Error(lastErrorMessage, exception);
    }

My problem is where do I specify the ServicePointManager.DefaultConnectionLimit ??

There is just one .asmx (and the .asmx.cs) file , which just contains the function that does my work. This function is supposed to call the other Web Service. This function is called every time the Web Service is Hit (multiple times in 1 second -- about 10), so I'm not sure I can specify the ServicePointManager.DefaultConnectionLimit here , since that would mean resetting it on every hit.

Also , this is hosted on a shared Server , So I don't want to mess with the Registry Key values , but I would be happy to make this change programmatically.

Any help would be greatly appreciated.


Solution

  • Just a thought Guys , can I put it in the protected void Application_Start(Object sender, EventArgs e){} ?

    Or is there something else that calls the Application_Start().

    is there anyway that I can determine the Starting Point of this WebService ? (From project properties or is it something default in WebServices ?)