Okay, I’ll try to make this as straight forward as possible. I’m using VB.Net in VS2010, I’m attempting to self-host a WCF service. (It’s actually in a windows service, but I’m trying to do this via a simple console app. Below is the code in question, the TCP/IP addresses are injected directly here. The WCF service itself is simply a renamed DEFAULT new WCF service project.
Dim host As New ServiceHost(GetType(TestService))
Dim tcpb As New NetTcpBinding()
tcpb.PortSharingEnabled = True
host.AddServiceEndpoint( _
GetType(ITestService), _
tcpb, _
"net.tcp://localhost:62020/TestWcfService/" _
)
host.Open()
Console.ReadKey(True)
host.Close()
I don’t think I can make this much simpler.. is there something special I need to do to get the port to actually bind? when I run netstat -a it doesn’t show a listening port on 62020 I am really at my whits end on this.
Background: I have another WCF service I’m trying to migrate out of IIS, and into a separate server running in a Windows Service. The WCF service will only be accessed internally. I’ve been having numerous issues in getting that migrated, so trying to get a simple service to bind, and have a client (website) access it. The other WCF is binding (different port) fine, but having communications errors. There is a literal ****-ton of stuff out there, and very little really fits my needs, and I’m having a lot of trouble getting anything working with it.
I just had the exact same problem when testing a new service. Turns out I had simply forgot to mark the service interface with the [ServiceContract] attribute. I guess WCF didn’t bother with creating an endpoint since no service contracts were found.
Would have been nice with an error message since I can’t imagine anyone wanting to open a ServiceHost without at least one contract being implemented, but I suspect this only happens when you are using simplified configuration in .NET 4.