I'm a bit confused of how to expose an endpoint in WCF
I've got a tcp endpoint and a mex tcp endpoint.
<service name="MessageReaderService.MessageReaderService">
<endpoint name="NetTcpReaderService"
address="ReaderService"
binding="netTcpBinding" bindingConfiguration=""
contract="Contracts.IMessageReaderService" />
<endpoint name="netTcpMex"
address="mex"
binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8082" />
</baseAddresses>
</host>
</service>
When I try to run this in the service host I get the following exception :
The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service MessageReaderService. Add a ServiceMetadataBehavior to the
configuration file or to the ServiceHost directly to enable support for this contract.
So I conclude from this error that I need to add a service behavior to expose metadata.
So I added the behavior :
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
but then I get a different error :
The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address. Either supply an http base address or set HttpGetUrl to an absolute address.
On a Windows computerPress the Windows key + R, then type "cmd.exe" and click OK. Enter "telnet + IP address or hostname + port number" (e.g., telnet www.example.com 1723 or telnet 10.17. xxx. xxx 5000) to run the telnet command in Command Prompt and test the TCP port status.
net. tcp is simply the URI scheme used within Windows to identify endpoints that can be accessed using TCP. Similarly, net. msmq and net. pipe , are the URI schemes to address endpoints that utilise the MSMQ protocol and Named Pipes protocol, respectively.
Short answer: Port 808 is used by the Net. TCP Port Sharing service, associated with Internet Information Services through the Windows Communication Foundation.
Address - where to call to - in your case net. tcp://localhost:25488/MyDataAccessService/MyFirstBindingAddress. Binding - what protocol and parameters to use (in your case: netTcpBinding ) Contract - the service contract (the public interface IMyDataAccessService ) to define the service methods and parameters needed.
Two things:
(1) once you've defined the service behavior, you of course must also apply it to the service!
<service name="MessageReaderService.MessageReaderService"
behaviorConfiguration="ServiceBehavior">
(2) you don't need an HTTP endpoint - you don't need to have an HTTP URL - just define this service behavior like this:
<behavior name="ServiceBehavior">
<serviceMetadata />
</behavior>
Your metadata is now available over a mexTcpBinding
endpoint - you cannot browse to it using HTTP, but a client can definitely connect to it and use it!
You can verify this by using the WCF Test Client and going to either
net.tcp://localhost:8082 (the base address)
or
net.tcp://localhost:8082/mex (the mex address)
in both cases, the WCF Test Client should now find your service and be able to discover its capabilities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With