How can I get the listening address / port of a WCF service?

I have a WCF service listening on a dynamically allocated port in the Windows Service Registry. How can I find the listening address of this service from another C # application? Or at least the port of this service?

Thanks Adriana

+1
c # wcf
Feb 05 '10 at 13:07
source share
1 answer

You can reset the actual "listeners" from within your service implementation after opening ServiceHost using the "ChannelDispatcher" property.

For example:

foreach (var channelDispatcher in serviceHost.ChannelDispatchers) { Console.WriteLine(channelDispatcher.Listener.Uri); } 

The listener URI will contain the TCP / IP port to which the service is sent. Please note that this, of course, is only valid for bindings that are based on TCP / IP in the first place. Also note that it is obvious that each service can have multiple listeners (or listener ports), so the ChannelDispatchers property can return multiple listeners.

You can also view / reset the value of the "Status" property to make sure that the corresponding channel manager is activated "Open", that is, listening.

Edit: You can also look at enabling WMI for WCF . Although I never considered this, he could also disclose such information.

If you cannot change the service code or do not want to, you need to resort to tools such as Process Explorer or netstat (later, assuming that you are using TCP / IP based bindings for service endpoints). Use the netstat "-b" parameter to display the PID and executable name for each port. This will give you a hint for your service (executable).

+7
Feb 08 '10 at 10:02
source share



All Articles