Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exposing net.tcp endpoint

Tags:

c#

wcf

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.

  1. So now I have to actually add another endpoint (http) to expose the metadata over mexhttpbinding ?
  2. is there a simple way to expose the endpoint over tcp ?
like image 392
eran otzap Avatar asked Apr 13 '12 16:04

eran otzap


People also ask

How can I tell if a TCP port is open?

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.

What is Net TCP?

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.

What port does NET TCP use?

Short answer: Port 808 is used by the Net. TCP Port Sharing service, associated with Internet Information Services through the Windows Communication Foundation.

How can I call TCP net WCF service?

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.


1 Answers

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.

like image 131
marc_s Avatar answered Sep 20 '22 17:09

marc_s