简体   繁体   English

Winforms中的NserviceBus

[英]NserviceBus in winforms

In my Program.cs 在我的Program.cs中

   public static IBus Bus { get; set; }

   [STAThread]
   static void Main()
   {
    Bus = Configure.With()
                .DefaultBuilder()
                .XmlSerializer()
                .MsmqTransport()
                .PurgeOnStartup(true)
                .UnicastBus()
                .SendOnly();

  var order = new PlaceOrder
            {
                OrderID = Guid.NewGuid(),
                ProductID = Guid.NewGuid(),
                CustomerID = Guid.NewGuid(),
            };


            Bus.Send(order);

   }

The Error I get: 我得到的错误:

No destination specified for message(s): MessagingContracts.PlaceOrder 没有为消息指定目的地:MessagingContracts.PlaceOrder

MessagingContracts.PlaceOrder is a class in a class library: MessagingContracts.PlaceOrder是类库中的一个类:

namespace MessagingContracts
{
    public class PlaceOrder:IMessage
    {

        public Guid CustomerID { get; set; }
        public Guid OrderID { get; set; }
        public Guid ProductID { get; set; }
    }
}

My end point is configured in app.config as: 我的端点在app.config中配置为:

  <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"></section>
  </configSections>

  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="MessagingContracts" Endpoint="MessagingEndPoint"></add>
    </MessageEndpointMappings>
  </UnicastBusConfig>

My endpoint class 我的终点班

namespace MessagingEndPoint
{
    public class EndPointConfig : IConfigureThisEndpoint, AsA_Server
    {
    }
}

How do i correct that error and see my message in my private queue(MessagingEndPoint)? 如何更正该错误并在我的私人队列(MessagingEndPoint)中看到我的消息? Any inputs on this error cause would be highly helpful. 关于此错误原因的任何输入将非常有帮助。

Okay, this one did the trick & mentioning the endpoint name(destination) along the send method passes the message to the queue. 好的,这个技巧很有趣,并在send方法中提到了端点名称(目的地),将消息传递到队列。

Bus.Send("MessagingEndPoint", order); //use this 

instead of 代替

 Bus.Send(order);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM