2

I am trying to send a command with NServiceBus 3.0. Everything works when I send a command that implements ICommand. However, it does not work if I use the conventions. The source is below. Can someone tell me what I am doing wrong?

public class Program
{
    public static NServiceBus.IBus Bus { get; private set; }

    static void Main(string[] args)
    {
        ConfigureBus();

        var command = new RouteTradeCommand() { TradeXml = "<trade />" };
        Bus.Send("BrokerQueue@DATPCDI041", command);
    }

    private static void ConfigureBus()
    {
        Bus = Configure.With()
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
            .UnicastBus()
            .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith("Messages"))
            .SendOnly();
    }
}

The command looks like this:

namespace Messages
{
    public class RouteTradeCommand : IRouteTradeCommand
    {
        public string TradeXml { get; set; }
    }   
}
Marijn
  • 10,367
  • 5
  • 59
  • 80
Rob Bagby
  • 139
  • 1
  • 7

1 Answers1

4

Unfortunately, NSB is dependent on the ordering of the config methods. It'll work if you move the DefiningCommandsAs method to right after With:

NServiceBus.Configure.WithWeb()
.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith(".Commands"))
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.DefineEndpointName("Web")
.UnicastBus()
.SendOnly();
Jonathan Matheus
  • 1,350
  • 2
  • 12
  • 15