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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:44:56+00:00 2026-05-18T21:44:56+00:00

WCF newbie here… I’m trying to self-host a WCF service using NetTcpBinding. Based on

  • 0

WCF newbie here… I’m trying to self-host a WCF service using NetTcpBinding. Based on the MSDN “how-to” tutorial I have done all the binding in code, which I then changed from WsHttpBinding to NetTcpBinding, and now looks like this:

var baseAddress = new Uri("net.tcp://localhost:8000/MyWebService");
var selfHost = new ServiceHost(typeof(ConcreteWebService), baseAddress);
try {
  var binding = new NetTcpBinding();
  binding.Security.Mode = SecurityMode.Message;
  selfHost.AddServiceEndpoint(typeof(IWebService), binding, "TRWebService");
  selfHost.Open();
  Console.WriteLine("The service is ready at {0}", baseAddress.AbsoluteUri);
  Console.WriteLine("Press <ENTER> to terminate service.");
  Console.WriteLine();
  Console.ReadLine();

  selfHost.Close();
} catch (CommunicationException ce) {
  Console.WriteLine("An exception occurred: {0}", ce.Message);
  selfHost.Abort();
}

Thing is, the tutorial then says you have to run svcutil.exe to generate a proxy for the client… but since I switched to NetTcpBinding, svcutil doesn’t work anymore – can’t detect my service. I googled the issue, and found that every single example out there of NetTcpBinding does the setup in the app.config file, not in code, and they all add an endpoint called “Mex”, with binding type of “mexTcpBinding”. There doesn’t appear to be any equivalent of this in code.

So, do I have to change my project to use app.config, and abandon the code-based approach? Can anyone explain to me what Mex is, why I need it, and why it (apparently) can’t be called in code – or if it can, how, or why is it discouraged? In general, when is it better to use app.config, and when code for WCF services?

  • 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-18T21:44:56+00:00Added an answer on May 18, 2026 at 9:44 pm

    If you use netTcpBinding – and in a “behind-the-corporate-firewall” LAN environment, it’s definitely a great idea to do so – you need to also expose a MEX endpoint (Metadata Exchange) using the mexTcpBinding in order for svcutil to be able to detect and find that service.

    MEX = Metadata Exchange is the mechanism that WCF uses to “publicly advertise” what a service looks like. If you have a MEX endpoint, then utilities like svcutil can query and “discover” a service, e.g. find out about all the service methods it exposes, about the parameters it expects to get and so on.

    To add a MEX endpoint, you can definitely use code, too! Something like this fragment:

    var mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
    selfHost.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "mex");
    

    Without MEX, you need to somehow “tell” the client trying to consume your service what it is your service offers so that the client can make sure to call the proper methods with the proper parameters.

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

Sidebar

Related Questions

I have a WCF service that I have to reference from a .net 2.0
I have a wcf application hosted in a windows service running a local windows
I have a WCF Web Service which is referenced from a class library. After
I'm a newbie with WCF services, and I'm trying to figure out if is
I am a newbie in WCF, currently I am developing a TCP WCF service
I'm a newbie with WCF. I had wcf service in iis running fine. I
I'm a newbie to WCF, trying to perform relatively simple task. I'm trying to
I have a WCF service that lives side-by-side with an MVC2 web site. I'd
My WCF service library, the console host for the service, and the client are
I have built a WCF Service that is being consumed by a Silverlight app.

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.