0

For some reason I'm unable to attach the Visual Studio 2010 debugger to my service which uses a WCF Service Library, I followed the MSDN tutorial from here. When I install and run the service it works just fine, and I'm able to access everything from a Client GUI, but when I try to attach the debugger to the service I get the following WCF Service Host window that pops up with an error:

System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:8000.  Make sure that you are not trying to use this endpoint multiple times in your application and that there are no other applications listening on this endpoint. ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.ServiceModel.Channels.SocketConnectionListener.Listen()
   --- End of inner exception stack trace ---
   at System.ServiceModel.Channels.SocketConnectionListener.Listen()
   at System.ServiceModel.Channels.ConnectionAcceptor.StartAccepting()
   at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()
   at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
   at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
System.Net.Sockets.SocketException (0x80004005): Only one usage of each socket address (protocol/network address/port) is normally permitted
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at System.ServiceModel.Channels.SocketConnectionListener.Listen()

The issue is happening on myServiceHost.open() in the OnStart() function in the service as seen below:

public partial class ORAS : ServiceBase
    {
        System.Timers.Timer aTimer;
        OWcfServiceLibrary.OService ORAS = new OService();
        internal static ServiceHost myServiceHost = null; 
        public ORAS()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            System.Diagnostics.Debugger.Launch();
            aTimer = new System.Timers.Timer(60000);//every minute
            aTimer.AutoReset = true;
            aTimer.Elapsed += new System.Timers.ElapsedEventHandler(aTimer_Has_Alarm);
            aTimer.Enabled = true;
            if (myServiceHost != null)
            {
                myServiceHost.Close();
            }
            myServiceHost = new ServiceHost(typeof(OrionService));
            myServiceHost.Open();
        }
Medic3000
  • 786
  • 4
  • 20
  • 44
  • How exactly are you "unable to attach"? Errors? Messages? What I like to do with services is have them auto-detect when they're running in interactive mode (e.g. manually from the command-line) so that they can be debugged easier. For more details http://bit.ly/LFEk6d – Peter Ritchie Aug 13 '13 at 17:25
  • I can attach to the service executable, but then the above message pops up – Medic3000 Aug 13 '13 at 17:37
  • here is the solution for your problem http://stackoverflow.com/questions/283145/how-to-prevent-visual-studio-launch-wcfsvchost-exe-in-debuggin – Abdu Jul 31 '14 at 06:43

1 Answers1

2

Looks to me like you have two attempts at something like serviceHost.AddServiceEndpoint(), where the 1st was the service itself, and then again when you started debug.

You can step into service code if you:

  1. Run Visual Studio "as Administrator".
  2. Have the service running and ready.
  3. Start your client code in debug and put a breakpoint on the line that calls into the service.

When your client code hits the breakpoint, use Step Into (F11) to move into service code. If you're setup correctly, it'll seamlessly translate into service code where you can continue stepping.

An alternative:

  1. Stop your service.
  2. In your service's OnStart() method, place this line first: System.Diagnostics.Debugger.Launch();
  3. Rebuild and then start the service
  4. When that new code line is hit, you will get prompted for choosing a debugger...choose the already open project

That should drop you on the new launch() line.

DonBoitnott
  • 10,787
  • 6
  • 49
  • 68
  • This seems like a solution, but my Service is not being called by a client, rather it is doing some timer based tasks in the service its self that I'd like to debug. So the client isn't ever running just the service.exe – Medic3000 Aug 13 '13 at 17:51
  • Updated answer with another option – DonBoitnott Aug 13 '13 at 17:56
  • BUUUUUT, on the start of my serviceHost the issue ooccures again. Question updated to include this – Medic3000 Aug 13 '13 at 18:16