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

  • Home
  • SEARCH
  • 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 9266195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:15:44+00:00 2026-06-18T14:15:44+00:00

I am writing a test WCF server with a method to add 2 numbers

  • 0

I am writing a test WCF server with a method to add 2 numbers and wait a configurable number of milliseconds.

I have written a wcf client. When I open two instances of this client – on clientA the wait value is 50 seconds and on the other clientB the wait is 0 seconds. I expect that when client A is running (long process) client B will get its response immediately.

It is however not working. I have been following this tutorial WCF Concurrency

Why is it not working for me?

WCF Service

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;


namespace WCFService
{
    //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,ConcurrencyMode = ConcurrencyMode.Multiple,UseSynchronizationContext = true)]
    //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,ConcurrencyMode = ConcurrencyMode.Single)] 
    //[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
    //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession,ConcurrencyMode = ConcurrencyMode.Multiple)]
    //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession,ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class WCFJobsLibrary : IWCFJobsLibrary
    {

        public ReturnClass AddNumbers(int FirstNumber, int SecondNumber, int Delay) //Add two numbers and wait a predefined interval
        {
            ReturnClass myReturnClass = new ReturnClass(-1, null, null, 0);
            try
            {             

                myReturnClass.ErrorCode = 1;
                myReturnClass.Result = FirstNumber + SecondNumber;
                System.Threading.Thread.Sleep(Delay); // Wait
                return myReturnClass;

            }
            catch (Exception ex)
            {              
                myReturnClass.ErrorCode = -1;
                myReturnClass.ErrorMessage = ex.ToString();
                return myReturnClass;
            }

        }

    }
}

WCF Client

try
            {

                radTextBoxResult.Text = ""; // Reset Result
                ServiceReference1.WCFJobsLibraryClient Client = new ServiceReference1.WCFJobsLibraryClient();
                Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(radTextBoxbaseAddress.Text);
                WCFClient.ServiceReference1.ReturnClass AddNumbers_Result;
                AddNumbers_Result = Client.AddNumbers(int.Parse(radTextBoxFirstNumber.Text), int.Parse(radTextBoxSecondNumber.Text), int.Parse(radTextBoxDelay.Text));


                if (AddNumbers_Result.ErrorCode < 0)
                {
                    // If exception happens, it will be returned here
                    MessageBox.Show(AddNumbers_Result.ErrorCode.ToString() + " " + AddNumbers_Result.ErrorMessage + " " + AddNumbers_Result.ExMessage);
                }

                else
                {

                    radTextBoxResult.Text = AddNumbers_Result.Result.ToString();

                }

            }

            catch (Exception ex)
            {

                MessageBox.Show(ex.Message.ToString());

            }

App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                  <serviceThrottling maxConcurrentCalls="16" maxConcurrentInstances="2147483647" maxConcurrentSessions="10" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service name="WCFService.WCFJobsLibrary">
                <endpoint address="" binding="wsHttpBinding" contract="WCFService.IWCFJobsLibrary">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:8732/Design_Time_Addresses/WCFService/WCFJobsLibrary/" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>
  • 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-18T14:15:45+00:00Added an answer on June 18, 2026 at 2:15 pm

    the problem was that i was starting the service in a winform application on the main thread. You need to start WCF on a seperate thread as illustrated below.

    C# Code

    private void radButtonStartWCFService_Click(object sender, EventArgs e)
    {
        try
        {
            Thread Trd = new Thread(() => StartWCFServer());
            Trd.IsBackground = true;
            Trd.Start();
    
            radButtonStartWCFService.Enabled = false;
            radButtonStartWCFService.Text = "WCF Server Started";
    
        }
    
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }
    }
    
    
    private void StartWCFServer()
    {
    
        try
        {
            sHost = new ServiceHost(typeof(WCFService.WCFJobsLibrary));
            sHost.Open();
    
        }
    
        catch (Exception ex)
        {
    
            MessageBox.Show(ex.Message.ToString());
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing test code to test a client-server application. The application under test consists
I have a WCF server that is a library assembly. (I am writing it
Im writting unit test for a WCF service which i have written. The thing
Hello I have a simple wcf service like this, with a test method which
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
i am writing a program to test WCF service performance in high concurrency circumstance.
I'm writing a WPF test application against a WCF REST service running on Azure
I'm writing test cases for a wrapper class written around ASIHTTPRequest . For reasons
Does anyone have some good hints for writing test code for database-backend development where
I am in the process of writing some test for a server that is

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.