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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:36:22+00:00 2026-06-09T14:36:22+00:00

I have a few questions regarding WCF: – Can a program act as both

  • 0

I have a few questions regarding WCF:
– Can a program act as both client and server ?
– What’s wrong with my code :

The service:

[ServiceContract]
public interface IShout
{
    [OperationContract]
    String Broadcast(String message);
}

The implementation:

public class eveShout : IShout
{
    public String Broadcast(String message)
    {
        return message + " reply";
    }
}

I start the service in the form contructor:

ServiceHost s = new ServiceHost(typeof(IShout));
s.AddServiceEndpoint(typeof(IShout), new BasicHttpBinding(), "http://localhost:9189");
s.Open();

The, When I click a button on another form, I want to send a message and get a reply back.
I use the following code:

ChannelFactory<IShout> channel = new ChannelFactory<IShout>(new BasicHttpBinding(), "http://localhost:9189");
IShout shout = channel.CreateChannel();

String reply = shout.Broadcast("Test");

Note: all the code is in the same namespace.
Note: I first start the “server” (open) then the app continues.

when i run the code, the server is created. I use netstat -a to see if the port is open. when I run the command, i get 9189 is in listening state. but the code stops at the command reply = shout(“test”). and I get anexception that says

The request channel timeout while waiting for a reply after 00:00:59…

  • 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-09T14:36:23+00:00Added an answer on June 9, 2026 at 2:36 pm

    Yes, you can have an app act as both client and server.

    I see a couple of things that may need correcting. First, try adding OperationContract.

    [ServiceContract]
    public interface IShout
    {
        [OperationContract]
        String Broadcast(String message);
    } 
    

    Then, take the type of the class, not the interface.

    ServiceHost s = new ServiceHost(typeof(eveShout));
    s.AddServiceEndpoint(typeof(IShout), new BasicHttpBinding(), "http://localhost:9189");
    s.Open(); 
    

    Make sure you you have permission to access the namespace (s.Open() should throw an exception if it does not).

    net http add urlacl url=http://+:9189/ user=...
    

    See if these suggestions help.

    (oh yeh, and make Broadcast public in your class)

    A quick example WindowsFormsApplication looks like this…

    // form1.cs
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.ServiceModel;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                ChannelFactory<IShout> channel = new ChannelFactory<IShout>(new BasicHttpBinding(), "http://localhost:9189");
                IShout shout = channel.CreateChannel();
    
                String reply = shout.Broadcast("Test"); 
    
            }
        }
    }
    
    // and Program.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;
    using System.ServiceModel;
    
    namespace WindowsFormsApplication1
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                ServiceHost s = new ServiceHost(typeof(eveShout));
                s.AddServiceEndpoint(typeof(IShout), new BasicHttpBinding(), "http://localhost:9189");
                s.Open(); 
    
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    
        public class eveShout : IShout
        {
            public String Broadcast(String message)
            {
                return message + " reply";
            }
        } 
    
        [ServiceContract]
        public interface IShout
        {
            [OperationContract]
            String Broadcast(String message);
        } 
    }
    

    See if you can get something as simple as this working. That will at least prove to you that it can be done and that the problem is somewhere else.

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

Sidebar

Related Questions

I have a few questions regarding JavaScript obfuscation on client side. First question :
I have a few questions regarding android source code download, repo / git. This
I have few questions regarding safety and correctness of following hypothetical timer service: @Singleton
I have a few questions regarding MySQL server running under Windows Server 2008 R2.
I have got few questions regarding creating windows service. I have created a windows
I have a few questions regarding my DIV layout. I can't seem to understand
I have a few questions regarding android market(Google play). How can I list my
I have a few questions regarding sql server in android. Essentially, I am tring
I am a newbie user of Frama-C and have a few questions regarding assertions
I'm very new to TDD world. I have a few questions regarding TDD. Do

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.