これまでのところ、私が見つけた唯一の解決策は、の Message パラメータでリフレクションを使用することですAfterReceiveRequest
。それは機能しますが、これが公共の財産として表面化されていないのは奇妙に思えます。
class MsmqLookupIdBehavior : IDispatchMessageInspector
{
static PropertyInfo lookupIdPropertyInfo;
static MsmqLookupIdBehavior()
{
try
{
var type = typeof(MsmqMessageProperty);
lookupIdPropertyInfo = type.GetProperty("LookupId", BindingFlags.NonPublic | BindingFlags.Instance);
}
catch { }
}
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
if (lookupIdPropertyInfo != null)
{
var lookupIds =
request.Properties.Values
.Where(p => p is MsmqMessageProperty)
.Select(p => lookupIdPropertyInfo.GetValue(p))
.Where(v => v is long)
.Select(v => (long)v);
foreach (var lookupId in lookupIds)
{
// Use lookupId here
}
}
return null;
}
// The rest of IDispatchMessageInspector here, not relevant for this behavior
}