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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:18:16+00:00 2026-05-13T01:18:16+00:00

I am trying to host a WCF service, using NetTcpBinding in a Windows service.

  • 0

I am trying to host a WCF service, using NetTcpBinding in a Windows service. (I’m going to use it as an API for various clients both Web and Windows32) Obviously, I am doing this within a test host before putting it in a Windows service.

I have the following contract:

namespace yyy.xxx.Server.API.WCF
{
    [ServiceContract]
    public interface ISecureSessionBroker
    {
        [OperationContract]
        string GetSessionToken(string username, string encryptedPassword, string clientApiKey, string clientAddress);
    }
}

with the following implementation:

namespace yyy.xxx.Server.API.WCF
{
    public class SecureSessionBroker : ISecureSessionBroker
    {
        #region ~ from ISecureSessionBroker ~

        public string GetSessionToken(string username, string encryptedPassword, string clientApiKey, string clientAddress)
        {
            return Guid.NewGuid().ToString();
        }

        #endregion
    }
}

I am hosting the WCF service using the code below (within a class/method):

try
{
    _secureSessionBrokerHost = new ServiceHost(typeof(SecureSessionBroker));
    NetTcpBinding netTcpBinding = new NetTcpBinding();
    _secureSessionBrokerHost.AddServiceEndpoint(typeof(ISecureSessionBroker), netTcpBinding, "net.tcp://localhost:8080/secureSessionBrokerTcp");
    int newLimit = _secureSessionBrokerHost.IncrementManualFlowControlLimit(100);
    // Open the ServiceHost to start listening for messages.
    _secureSessionBrokerHost.Open();

}
catch (Exception ex)
{
throw;
}

The key thing here is that I do not want to have to rely on an App.config file. Everything must be configured programmatically. When I run this code, the service appears to come “up” and listen. (ie. I have no exceptions)

BUT when I use the client code below:

string secureSessionBrokerUrl = string.Format("{0}/secureSessionBrokerTcp","net.tcp://localhost/8080",url);
EndpointAddress endpointAddress=new EndpointAddress(secureSessionBrokerUrl);
System.ServiceModel.Channels.Binding binding = new NetTcpBinding();
yyy.xxx.Windows.AdminTool.API.WCF.SecureSessions.SecureSessionBrokerClient
    client = new yyy.xxx.Windows.AdminTool.API.WCF.SecureSessions.SecureSessionBrokerClient(binding,endpointAddress);
string sessionToken=client.GetSessionToken("", "", ""); // exception here
MessageBox.Show(sessionToken);

… I always get an exception. At the moment, I am getting:

This request operation sent to
net.tcp://localhost:8080/secureSessionBrokerTcp
did not receive a reply within the
configured timeout (00:01:00). The
time allotted to this operation may
have been a portion of a longer
timeout. This may be because the
service is still processing the
operation or because the service was
unable to send a reply message.
Please consider increasing the
operation timeout (by casting the
channel/proxy to IContextChannel and
setting the OperationTimeout property)
and ensure that the service is able to
connect to the client.

So I guess it cannot resolve the service.

Where am I going wrong? How do I test for the existence of the service over TCP? I have used the SvcTraceViewer and I just get the same message, so no news there.

I would prefer to ask the user for a URL of the service, so they would enter “net.tcp://localhost:8080” or something, which would then be used as a BaseAddress for the various calls to the SecureSessionBroker (and other) WCF services … without resorting to App.config.

Unfortunately, all the examples I can find all use the App.config.

Interestingly, I can host the service using the VS Host and the client connects fine. (Using:
D:\dev2008\xxx\yyy.xxx.Server>WcfSvcHost.exe /service:bin/debug/yyy.
xxx.Server.dll /config:App.config)

  • 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-13T01:18:17+00:00Added an answer on May 13, 2026 at 1:18 am

    Ok, it came to me in a flash of inspiration.

    I was using a Windows Form (alarm bells) to “host” the service. Clicking out of the form, I used a bit of code to call the service (included) on a button click. Of course, the service was not in its own thread, so the service could not respond.

    I’ve fixed it by putting the Service container (which contains the host) within its own thread:

    Thread thread = new Thread(new ThreadStart(_serviceWrapper.Start));
    thread.Start();
    

    The Start() method sets up the ServiceHost.

    I incorrectly thought that while a WCF Service Host will create threads for incoming requests, it will only do this if it is in its own non-blocking thread (ie. not a UI thread).

    Hope it helps someone else.

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

Sidebar

Related Questions

I'm trying to build a C++ extension for python using swig. I've followed the
I am trying to redirect to a specific path based on HTTP_HOST or SERVER_NAME
I'm trying to write test harness for part of my Android mapping application. I
I'm trying to build a Chrome browser extension, that should enhance the way the
I am trying to load a html page through UIWebview.I need to disable all
I am trying to understand the practical difference during the execution of a program
I am playing with TFS 2010, and am trying to setup a build process
I have several USB mass storage flash drives connected to a Ubuntu Linux computer

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.