Question

I need to provide two endpoints on a self hosted WCF service. This because I am connecting to it through two different connections, one for LAN connection, one for incoming internet connections.

My BasicHttp endpoint has always worked and I am now trying to add the TCP endpoint as .Net tells me I can't have more than one http endpoint/binding...

My service starts without error, with both endpoints configured.

Dim serviceAddyArray(1) As Uri

Dim myServiceAddressLOCAL As New Uri("http://" & localIpAddress & ":" & tcp_port & "/" & servicename)

serviceAddyArray(0) = myServiceAddressLOCAL

Dim myServiceAddressONLINE As New Uri("net.tcp://" & "10.0.0.101" & ":" & 5416 & "/" & servicename)

serviceAddyArray(1) = myServiceAddressONLINE

'myservicehost = New ServiceHost(GetType(plutocomm), myServiceAddress)

myservicehost = New ServiceHost(GetType(plutocomm), serviceAddyArray)


Dim BasicBinding As New BasicHttpBinding
BasicBinding.MaxReceivedMessageSize = 2147483647

Dim TCPBinding As New NetTcpBinding
TCPBinding.MaxReceivedMessageSize = 2147483647

'add local endpoint
myservicehost.AddServiceEndpoint(GetType(Iplutocomm), BasicBinding, myServiceAddressLOCAL)

'add online endpoint
myservicehost.AddServiceEndpoint(GetType(Iplutocomm), TCPBinding, myServiceAddressONLINE)


 ' Enable metadata publishing.
 Dim smb As New ServiceMetadataBehavior()
 smb.HttpGetEnabled = True
 smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15
 myservicehost.Description.Behaviors.Add(smb)

 myservicehost.Open()

For testing purposes, I set the ONLINE endpoint (internet) to my local IP, to eliminate any firewall issues.

When using the Add Service Reference wizard/tool from within visual studio, I can't connect to the TCP binding, on net.tcp://10.0.0.101:5416/pluto

I get the following error when trying to find the binding with the tool.

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://10.0.0.101:5416/pluto'.
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:04:59.9989993'.
An existing connection was forcibly closed by the remote host
If the service is defined in the current solution, try building the solution and adding the service reference again.

Note:

With he above self hosted implementation, I CAN connect to and use the basicHttpBinding endpoint.

Was it helpful?

Solution

You need to add a mexTcpEndpoint that the "Add service reference wizard" can use to get the WSDL. Do this after you add the serviceMetadataBehavior.

serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                           MetadataExchangeBindings.CreateMexTcpBinding(),
                                           "net.tcp://localhost:6666/Service/mex");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top