到目前为止,我发现的唯一解决方案是对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
}