【发布时间】:2015-10-28 15:50:41
【问题描述】:
我正在尝试将原始 TestService 端点连接到原始 WCF 服务,其中 WCF 服务实例使用最新的 NSB 5.2.9/Host6.0 将原始 TestCommand 发送到 TestService 端点:
[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 托管。
- IIS WCF 主机应用程序的 web.config
- 通过 NServiceBus.Config.IConfigurationSource
- 通过 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 倍的拼写错误、大小写和所有内容。我清洗了溶液。 我的问题是:为什么 NServiceBus 找不到端点?
请帮忙。
【问题讨论】:
-
你能从 web.config 发布你的映射吗?
-
@TylerDay 谢谢,我更新了我的问题。要记住的是,我尝试使用 IConfigurationSource 和 IProvideConfiguration 使用 web.config 和 WTIHOUT 进行配置。这些都不起作用。谢谢!
-
您的 webconfig 映射了一个名为“RunTestCommand”的命令,而不是示例代码所示的“TestCommand”。
-
@TylerDay 不是这样。只是一个类型,同时匿名上面的代码。道歉。
标签: c# .net wcf nservicebus nservicebus5