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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:08:02+00:00 2026-05-25T15:08:02+00:00

public interface IConsoleData { double GetCurrentIndicator(); } public class IConsoleDataImpl : IConsoleData { public

  • 0
public interface IConsoleData
{
    double GetCurrentIndicator();
}

public class IConsoleDataImpl : IConsoleData
{
    public double GetCurrentIndicator()
    {
        return 22;
    }
}

[ServiceContract]
public interface IMBClientConsole
{
    [OperationContract]
    IConsoleData GetData();
}

public class MBClientConsole : IMBClientConsole
{
    public IConsoleData GetData()
    {
        return new IConsoleDataImpl();
    }
}

class Log
{

    public static void initialize()
    {
        using (ServiceHost host = new ServiceHost(typeof(MBClientConsole),
          new Uri[]{
      new Uri("net.pipe://localhost")
    }))
        {
            host.AddServiceEndpoint(typeof(MBClientConsole),
              new NetNamedPipeBinding(),
              "PipeReverse");

            host.Open();
            // TODO: host.Close();
        }
    }
}

And when AddServiceEndpoint is called I receive

The contract type Commons.MBClientConsole is not attributed with
ServiceContractAttribute. In order to define a valid contract, the
specified type (either contract interface or service class) must be
attributed with ServiceContractAttribute.

But as you can see from my code interface is attributed with ServiceContract attribute. Why VS claims that it doesn’t and how to fix the problem?

Updated listing below:

public interface IConsoleData
{
    double GetCurrentIndicator();
}

public class IConsoleDataImpl : IConsoleData
{
    public double GetCurrentIndicator()
    {
        return 22;
    }
}

[ServiceContract]
public interface IMBClientConsole
{
    [OperationContract]
    IConsoleData GetData();
}

public class MBClientConsole : IMBClientConsole
{
    public IConsoleData GetData()
    {
        return new IConsoleDataImpl();
    }
}

class Log
{

    private ServiceHost _host;

    public void initialize()
    {
        _host = new ServiceHost(typeof (MBClientConsole),
                                new Uri[]
                                    {
                                        new Uri("net.pipe://localhost")
                                    });
            _host.AddServiceEndpoint(typeof(IMBClientConsole),
              new NetNamedPipeBinding(),
              "PipeReverse");

            _host.Open();
            System.Threading.Thread.Sleep(1000000);
            // TODO: host.Close();
    }
}

Client:

public interface IConsoleData
{
    double GetCurrentIndicator();
}

[ServiceContract]
public interface IMBClientConsole
{
    [OperationContract]
    IConsoleData GetData();
}

class Program
{
    static void Main(string[] args)
    {
        ChannelFactory<IMBClientConsole> pipeFactory =
            new ChannelFactory<IMBClientConsole>(
                new NetNamedPipeBinding(),
                new EndpointAddress(
                    "net.pipe://localhost/PipeReverse"));

        IMBClientConsole pipeProxy =
          pipeFactory.CreateChannel();

        while (true)
        {
            string str = Console.ReadLine();
            Console.WriteLine("pipe: " +
              pipeProxy.GetData().GetCurrentIndicator());
        }
    }
}

I still receive CommunicationException “There was an error reading from the pipe: The channel was closed. (109, 0x6d).”

  • 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-25T15:08:03+00:00Added an answer on May 25, 2026 at 3:08 pm

    change

    host.AddServiceEndpoint(typeof(MBClientConsole),
                  new NetNamedPipeBinding(),
                  "PipeReverse");
    

    to

    host.AddServiceEndpoint(typeof(IMBClientConsole),
                  new NetNamedPipeBinding(),
                  "PipeReverse");
    

    the second needs the Service-Contract (=Interface) not the implementation. Sometimes they are the same but not here.

    With

    using (ServiceHost host = new ServiceHost(typeof(MBClientConsole),
      new Uri[]{new Uri("net.pipe://localhost")}))
    

    you say WCF what “object” to create (MBClientConsole) when the service is called (and the base-Address of the service) but with the AddServiceEndpoint you tell WCF what Service-Contract to expose. I hope you can make any sense from that 😉

    You have a bug in your code:

    public static void initialize()
    {
        using (ServiceHost host = new ServiceHost(typeof(MBClientConsole),
          new Uri[]{new Uri("net.pipe://localhost")}))
        {
            host.AddServiceEndpoint(typeof(IMBClientConsole),
              new NetNamedPipeBinding(),
              "PipeReverse");
    
            host.Open();
            // TODO: host.Close();
        }
    }
    

    since you are using using(Service host ... the host object will be disposed if you leef the Initialize-Method. I guess you copied this from a ConsoleHost-Example. Move the host into a field and use something like this:

    class Log
    {
    
        ServiceHost _host;
        public void Initialize()
        {
          _host = new ServiceHost(typeof(MBClientConsole),
              new Uri[]{new Uri("net.pipe://localhost")});
    
          _host.AddServiceEndpoint(typeof(IMBClientConsole),
                  new NetNamedPipeBinding(),
                  "PipeReverse");
    
          _host.Open();
        }
    
        public void Close()
        {
           _host.Close();
           _host.Dispose();
        }
    }
    

    REMARKS: you made everything static (copied as I said) – I removed this. You might even think about implementing IDisposable (recommended) but I will leave this to your. You have to use this slightly different like

    var log = new Log();
    log.Initialize();
    

    and before quiting your program:

    log.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[ServiceContract] public interface ISecurities<T> : IPolicyProvider where T: EntityObject { [OperationContract(Name=GetAllSecurities)] IEnumerable<T> GetSecurities(); [OperationContract]
I have an interface public interface IDataProvider { T GetDataDocument<T>(Guid document) where T:class, new()
Publisher Interface [ServiceContract] public interface IPublisherInterface { [OperationContract(IsOneWay = false)] void Publish(MessageClass e, string
Assume my WCF interface declared like that: [ServiceContract] public interface IManagementConsole { [OperationContract] ConsoleData
WCF Service INTERFACE : [ServiceContract] public interface ITest { [OperationContract] int TestCall(GenericType<MyType> x); [OperationContract]
public interface ITest { void Somethink(); } public class Test1 : ITest { public
I have an interface: public interface IMyInterface { } I have a class which
Given the following code: public interface IExample { ... } public abstract class BaseExample:
I have an interface: public interface IMech { } and a class that implements
The classes: public interface Inter { ...some methods... } public class Impl implements Inter

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.