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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:46:43+00:00 2026-06-01T07:46:43+00:00

I created a WCF rest service, then called that from javascript using ajax. Now

  • 0

I created a WCF rest service, then called that from javascript using ajax. Now I want this service to be executed asynchronously, but it should also have access to session variables.

 [ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "/DoWork")]
    void DoWork();

}

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IService
{
    public void DoWork()
    {

        System.Threading.Thread.Sleep(15000); // Making some DB calls which take long time.
        try
        {

            HttpContext.Current.Session["IsCompleted"] = "True"; // Want to set a value in session to know if the async operation is completed or not.
        }
        catch
        {
        }
    }
}

Web.Config =

   <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <bindings>
      <webHttpBinding>
        <binding name="Rest_WebBinding">
          <security mode="Transport">
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="Rest">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="AsyncHost.Services.ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="AsyncHost.Services.ServiceBehavior" name="AsyncHost.Services.Service">

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <endpoint behaviorConfiguration="Rest" binding="webHttpBinding" contract="AsyncHost.Services.IService" />
      </service>
    </services>
  </system.serviceModel>
  <system.web>

I consumed this service from javascript like as below,

$.ajax({
                type: "POST",
                async: true,
                contentType: "application/json",
                url: 'http://localhost:34468/Services/Service.svc/DoWork',
                data: null,
                cache: false,
                processData: false,
                error: function () {
                    alert('Error');
                }
            });

    setTimeout("window.location.href = 'SecondPage.aspx';", 200);

Here I am not worried about the response of this service but it should update session variable after its completion as I have commented in the service implementation.

After calling this service I want to get it redirected to secondpage.aspx and the async service call should keep executing in the background.
But in the above case its waiting for complete execution of the service (i.e. executing synchronously) and then redirecting to the secondpage.aspx.
Let me know if there are any other ways to implement this.

  • 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-01T07:46:45+00:00Added an answer on June 1, 2026 at 7:46 am

    You may just return a boolean value from your service. Before returning the boolean response, just start a new thread and do the background job.

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

Sidebar

Related Questions

I have created a REST service using WCF for communicating with BLL/DAL from UI.
I have created a WCF REST Search Service, and now want to know how
I created a WCF service (.NET 3.5) that grabs data from a db and
So I'm trying to create a C# WCF REST service that is called by
I created a new wcf rest service using .net 4. I have created a
I've created a self-hosted WCF REST service (with some extra's from WCF REST Starter
I have a serializable dictionary that I created for a WCF REST web service
I have created a REST web service using WCF and use HTTP Post Method.
I created a wcf Rest service using net framework 4 and IIS 6. I
I created a WCF REST (aka WebHttp) service in .NET 4, using Microsoft's WCF

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.