最新の NSB 5.2.9/Host6.0 を使用しTestService
て、WCF サービス インスタンスがプリミティブTestCommand
をエンドポイントに送信するプリミティブ エンドポイントをプリミティブ WCF サービスに接続しようとしています。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>
「目立たないモード」: 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 がエンドポイントを見つけられないのですか?
助けてください。