3

我正在尝试将原始TestService端点连接到原始 WCF 服务,其中 WCF 服务实例使用最新的 NSB 5.2.9/Host6.0 将原始端点发送TestCommandTestService端点:

[ServiceBehavior(
    InstanceContextMode = InstanceContextMode.PerCall,
    ConcurrencyMode = ConcurrencyMode.Single )]
public class MyService : IMyService
{
    private readonly IBus bus;

    public MyService( IBus bus )
    {
        this.bus = bus;
    }

    public void Test( string value )
    {
        bus.Send( new TestCommand( value ) );
    }
}

我无法正确配置它。错误信息:

Exception thrown: 'System.InvalidOperationException' in System.ServiceModel.dll

Additional information: No destination could be found for message type Company.App.Commands.TestCommand. Check the <**MessageEndpointMappings**> section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.

我可以在不使用“不显眼的节点”的情况下做到这一点,但不能使用约定。在我尝试了一切之后,我对如何配置它感到非常困惑。WCF 主机是自托管的,而测试端点由 NServiceBus.Host 托管。

  1. IIS WCF 主机应用程序的 web.config
  2. 通过 NServiceBus.Config.IConfigurationSource
  3. 通过 NServiceBus.Config.IProvideConfiguration

现在我在 web.config 中有这个,这似乎无用且被忽略:

<MessageEndpointMappings>
    <add Assembly="Company.App.Messages" Type="Company.App.Commands.TestCommand" Endpoint="testservice" />
</MessageEndpointMappings>

“Unobtrusive mode”:我为约定创建了一个单独的项目,由 WCF 主机端点和 TestService 端点引用。

public class MessageConventions : INeedInitialization
{
    public void Customize( BusConfiguration configuration )
    {
        var conventions = configuration.Conventions();

        conventions.DefiningCommandsAs( t => t.Namespace != null && t.Namespace.StartsWith( "Company.App" ) && t.Namespace.EndsWith( "Commands" ) );
        conventions.DefiningEventsAs( t => t.Namespace != null && t.Namespace.StartsWith( "Company.App" ) && t.Namespace.EndsWith( "Events" ) );
        conventions.DefiningMessagesAs( t => t.Namespace != null && t.Namespace.StartsWith( "Company.App" ) );

        //conventions.DefiningTimeToBeReceivedAs( t => GetTimeToBeReceived( t ) )
        //conventions.DefiningDataBusPropertiesAs( pi => IsDataBusProperty( pi ) );
    }
}

这些约定似乎被TestService.

我的理解是 IIS WCF 主机必须在其 web.config 中声明映射,以便 WCF 服务知道将消息发送到哪里,bus.Send(new TestCommand("test"));但这不起作用。

然后我尝试在两个端点中定义这些映射,但没有运气。

此方法将输出使用上述约定找到的所有消息类型:

public class Startup : IWantToRunWhenBusStartsAndStops
{
public MessageMetadataRegistry Messages { get; set; }
public Conventions Conventions { get; set; }

public void Start()
{
    var getAllMessagesMethod = typeof( MessageMetadataRegistry ).GetMethod( "GetAllMessages",
        BindingFlags.NonPublic | BindingFlags.Instance );

    var allMessages = getAllMessagesMethod.Invoke( Messages, new object[ 0 ] ) as IEnumerable<MessageMetadata>;

    foreach ( var metadata in allMessages )
    {
        Type type = metadata.MessageType;
        string name = type.FullName;

        if ( this.Conventions.IsInSystemConventionList( type ) )
            Console.WriteLine( "System Msg: {0}", name );
        else if ( this.Conventions.IsCommandType( type ) )
            Console.WriteLine( "   Command: {0}", name );
        else if ( this.Conventions.IsEventType( type ) )
            Console.WriteLine( "     Event: {0}", name );
        else if ( this.Conventions.IsMessageType( type ) )
            Console.WriteLine( "   Message: {0}", name );

        if ( metadata.TimeToBeReceived != TimeSpan.MaxValue )
            Console.WriteLine( "            TimeToBeReceived={0}", metadata.TimeToBeReceived );
    }
}

public void Stop()
{
}
}

上面的方法输出消息类型“TestCommand”,因此它知道所做的约定。

我已经检查了 1000 倍的拼写错误,大小写,everyhting。我清洗了溶液。 我的问题是:为什么 NServiceBus 找不到端点?

请帮忙。

4

1 回答 1

1

Unobtrusive 意味着您按照约定告诉 NServiceBus 哪些类是命令和事件,而不是实现标记接口,您仍然需要在 app/web 配置中添加消息映射,以便 NServiceBus 知道将消息发送到哪个队列。

例外是暗示这是你的问题

Check the <**MessageEndpointMappings**> section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.

确保您的 web.config 中仍然有类似的内容:

<UnicastBusConfig>
  <MessageEndpointMappings>
    <add Messages="Company.App.Commands.TestCommand, Company.App.Commands" Endpoint="test.server" />
  </MessageEndpointMappings>
</UnicastBusConfig>

编辑

现在您已经发布了 web.config,问题看起来像是您在 web.config 中的类型名称错误:

<add Assembly="Company.App.Messages" Type="Company.App.Commands.RunTestCommand"

但你正在这样做bus.Send(new TestCommand(value));

所以web.config是错误的,应该是

<add Assembly="Company.App.Messages" Type="Company.App.Commands.TestCommand"
于 2015-10-28T16:24:43.350 回答