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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:27:23+00:00 2026-06-01T00:27:23+00:00

I am working on a simple WCF service, MiniCalcService which has only one operation

  • 0

I am working on a simple WCF service, MiniCalcService which has only one operation Add. The client and host are both console applications. The client application takes in the operands necessary for each operation and passes them over to the service. The service returns the result which would be displayed on the client console.

  • Host is running
  • I am doing everything in code so far and there is no app.config.
  • There is no large data being passed, just two or three numbers

This worked for me yesterday. Today when I tried the same thing, it throws the following exception:

There was no endpoint listening at http://localhost:8091/MiniCalcService that could accept the message.

Here is the Stack Trace. Not that it might matter, but MiniCalcClient is developed in Visual Studio and MiniCalcService and MiniCalcHost are developed in SharpDevelop.

MiniCalcHost:

using(ServiceHost host = new ServiceHost(typeof(MiniCalcService.Service), new Uri("http://localhost:8091/MiniCalcService")))
{
    host.AddServiceEndpoint(typeof(MiniCalcService.IService),new BasicHttpBinding(),"Service");

    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    host.Description.Behaviors.Add(smb);

    host.Open();
    Console.WriteLine("Serving MiniCalcService since {0}", DateTime.Now);
    Console.Write("Press ENTER key to terminate the MiniCalcHost . . . ");
    Console.ReadKey(true);
}

MiniCalcClient:

static string Calculator(string operation, params string[] strOperands)
{
    EndpointAddress ep = new EndpointAddress("http://localhost:8091/MiniCalcService");
    IService proxy = ChannelFactory<IService>.CreateChannel(new BasicHttpBinding(), ep);

    int[] operands;
    string result = string.Empty;

    try { operands = Array.ConvertAll(strOperands, int.Parse); }
    catch (ArgumentException) { throw; }

    switch (operation)
    {
        case "add":
            result = Convert.ToString(proxy.Add(operands));//<---EXCEPTION 
            break;
        default:
            Console.WriteLine("Why was this reachable again?");
            break;
    }

    return result;
}

Service Contract IService:

[ServiceContract(Namespace="learning.wcf.MiniCalc")]
public interface IService
{
    [OperationContract]
    double Add(params int[] operands);
}

Can you please help me identify what’s causing this exception?


Solution: I changed this line:

EndpointAddress ep = new EndpointAddress("http://localhost:8091/MiniCalcService");

to this:

EndpointAddress ep = new EndpointAddress("http://localhost:8091/MiniCalcService/Service");

and it worked.

  • 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-01T00:27:24+00:00Added an answer on June 1, 2026 at 12:27 am

    I’m not sure if you can use the params in a WCF service call…. seems unnecessary, anyway….

    Could you try these two service contracts instead, just to see if those would work:

    [ServiceContract(Namespace="learning.wcf.MiniCalc")]
    public interface IService2
    {
        [OperationContract]
        int Add(int op1, int op2);
    }
    

    and

    [ServiceContract(Namespace="learning.wcf.MiniCalc")]
    public interface IService3
    {
        [OperationContract]
        int Add(List<int> operands);
    }
    

    I’m just wondering if removing the params from your service contract might make it run – everything seems fine at first glance…


    OK, so it wasn’t this first attempt ……


    Well – quite obvious, really: you’re using a using block around the service host instantiation:

    using(ServiceHost host = new ServiceHost(typeof(MiniCalcService.Service), new Uri("http://localhost:8091/MiniCalcService")))
    {
        host.AddServiceEndpoint(typeof(MiniCalcService.IService),new BasicHttpBinding(),"Service");
    
        ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
        smb.HttpGetEnabled = true;
        host.Description.Behaviors.Add(smb);
    
        host.Open();
        Console.WriteLine("Serving MiniCalcService since {0}", DateTime.Now);
        Console.Write("Press ENTER key to terminate the MiniCalcHost . . . ");
    }
    

    So by the time the code reaches the closing bracket }, the ServiceHost instance will be disposed and thus the service host closed. There’s no running service host anymore!

    You need to stop the code execution somewhere after the call to host.Open() by e.g.

    Console.ReadLine();
    

    or something else.

    So your first claim that Host is running really doesn’t hold up – it’s running briefly and then is terminated again right away…..

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

Sidebar

Related Questions

I am trying to get a WCF Service working so it has simple message
I have a simple WCF4 REST service which is working fine when using a
I am building a simple WCF service that has to return some data from
I'm running Windows 7 64-bit. I'm attempting to host a WCF service which will
I have a working skeleton WCF service. I want to host it in a
I'm working on a simple plug-in framework. WCF client need to create an instance
I have a simple .NET 4 WCF service which I have hosted locally on
Running a simple JQuery.get (Version 1.6.2) against a C# WCF Service which returns a
We have a simple WCF (on .NET 4.0) Service which uses Windows authentication and
I have simple test (WPF - MVVM) client (for WCF oData service) app: ViewModel

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.