views:

274

answers:

4

Hi,

I have a WCF host that listen to a topic and process incoming messages. the code look this:

 using (ServiceHost host = new ServiceHost(MessagingServiceType))
 {
               host.Open();
}

and the MessagingServiceType looks like that:

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
    public class MessagingServiceType : IMessagingService
    {
        /// <summary>
        /// service instance
        /// </summary>
        private readonly MessagingService service;

        /// <summary>
        /// Initializes a new instance of the <see cref="MessagingServiceType"/> class.
        /// </summary>
        public MessagingServiceType()
        {
            // creating new messaging service
            service = new Singleton<MessagingService>();
        }

        /// <summary>
        /// Sends the message.
        /// </summary>
        /// <param name="messageContent">Content of the message.</param>
        public void SendMessage(string messageContent)
        {
            Message msg = Message.CreateMessage(MessageVersion.Default, string.Empty, messageContent);

            service.MessageReceived(msg);
        }
    }

The issue is that when i'm running it on a seperate test application, everything works fine and all the service receive all messages. However, when i take the exact same code and put it into my REAL application, no messages are being received.

my question is very simple: how can i "debug" this service to see what's wrong with it and why messages are not being processed? is there anyway to compare between the two?

Thanks

+1  A: 

Several options:

  • You can attach your Visual Studio debugger into your service host
  • You can to create some message inspector to check received messages
  • You can use a packet sniffer, but this seems to be an overkill.

Just make sure your service is up and running (no errors thrown from your host) and if you copied all relevant setup information from your development .config file.

Rubens Farias
+1  A: 

Visual Studio offers the ability to attach to remote processes for the purposes of debugging. It will require you to have the Visual Studio Remote Debugging Monitor running on the remote computer.

From visual studio, you can go to Debug / Attach To Process. From the dialog that comes up, you'll see a Qualifier tag that allows you to put in the remote server name. Once you put it in, you can attach to the process for your WCF service. If your service is hosted through IIS, you probably want to attach to the w3wp.exe process.

This will allow you to set breakpoints in your code in the service methods, and when the remote service executes those methods the breakpoints will be hit. It's important that your code be totally in sync with the code on the remote server, otherwise, your lines will be off as you step through the debugger.

Here's a link that also has some tips: http://geekswithblogs.net/TimH/archive/2006/08/08/87355.aspx

dcp
+3  A: 

Sure your service won't receive anything.... just look at your code:

 using (ServiceHost host = new ServiceHost(MessagingServiceType))
 {
               host.Open();
 }

What exactly happens when you reach the "}" ?? The object in the "using" clause - your ServiceHost - will be freed / disposed of! ==> before you know it, your service is gone again.....

You need to do something like:

ServiceHost host = new ServiceHost(MessagingServiceType);
host.Open();

Console.ReadLine();  // wait for a ENTER press
host.Close();

No big debugging needed........ :-)

marc_s
+1, omg, nice catch =)
Rubens Farias
Yeah that was my comment.....assumed there was more code they left out in the using block.
CSharpAtl
thanks, so clear...
Or A
A: 

Configuring Tracing and using the Service Trace Viewer can often show you where the issue is.

Once, of course, you make sure the server stays running as per marc_s' answer.

Jesse C. Slicer