I m使用NSERBus 3,当我收到电文时,我会从接收点看到这一错误:
NServiceBus.Unicast.Transport.Transactional.TransactionalTransport [(null)] <(null)> - Failed raising transport message received event for message with ID=97d0f2fa-6227-439b-ad37-a304bd2af00010428
System.NullReferenceException: Object reference not set to an instance of an object.
at NServiceBus.MessageHeaders.MessageHeaderManager.GetHeader(Object message, String key)
at NServiceBus.MessageHeaders.Bootstrapper.<Run>b__0(Object msg, String key)
at NServiceBus.ExtensionMethods.GetHeader(Object msg, String key)
at NServiceBus.ExtensionMethods.GetOriginatingSiteHeader(Object msg)
at NServiceBus.Gateway.HeaderManagement.GatewayHeaderManager.MutateIncoming(Object message)
at NServiceBus.Unicast.UnicastBus.<>c__DisplayClass25.<ApplyIncomingMessageMutatorsTo>b__24(IMutateIncomingMessages m)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at NServiceBus.Unicast.UnicastBus.ApplyIncomingMessageMutatorsTo(IBuilder builder, Object originalMessage)
at NServiceBus.Unicast.UnicastBus.<>c__DisplayClass22.<HandleMessage>b__21(Object msg)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at NServiceBus.Unicast.UnicastBus.HandleMessage(IBuilder builder, TransportMessage m)
at NServiceBus.Unicast.UnicastBus.HandleTransportMessage(IBuilder childBuilder, TransportMessage msg)
at NServiceBus.Unicast.UnicastBus.TransportMessageReceived(Object sender, TransportMessageReceivedEventArgs e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at NServiceBus.Unicast.Transport.Transactional.TransactionalTransport.OnTransportMessageReceived(TransportMessage msg)
这一信息本身就是这样:
public interface ILinkPersonMessage : IBaseMessage
{
int PersonId { get; set; }
List<int> UnitIds { get; set; }
}
public interface IBaseMessage
{
int UserId { get; set; }
}
在派出一级:
var message = bus.CreateInstance<ILinkPersonMessage>();
message.UserId = currentUser.UserId;
message.PersonId = personId;
message.UnitIds = selectedUnits;
bus.Send(message);
<>Update:
I m 追随《NSERBus法典》,这是造成错误的方法:
public string GetHeader(object message, string key)
{
if (message == ExtensionMethods.CurrentMessageBeingHandled)
if (bus.CurrentMessageContext.Headers.ContainsKey(key))
return bus.CurrentMessageContext.Headers[key];
else
return null;
if (messageHeaders == null)
return null;
if (!messageHeaders.ContainsKey(message))
return null;
if (messageHeaders[message].ContainsKey(key))
return messageHeaders[message][key];
return null;
}
从该守则来看,只有在以下情况下才能做到这一点:<条码>bus.CurrentMessageContext或bus.CurrentMessageContext.Headers
是无效的,或者messageHeaders[message]
存在,但含有无效价值。 不幸的是,我没有能够说明其中哪一种情况(甚至可能)更可能发生。
<<>上>
So using QueueExplorer 我把头盔推出:
<?xml version="1.0"?>
<ArrayOfHeaderInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HeaderInfo>
<Key>NServiceBus.Version</Key>
<Value>3.0.3</Value>
</HeaderInfo>
<HeaderInfo>
<Key>NServiceBus.TimeSent</Key>
<Value>2012-05-08 06:57:15:691208 Z</Value>
</HeaderInfo>
<HeaderInfo>
<Key>NServiceBus.EnclosedMessageTypes</Key>
<Value>Namespace.Service.ILinkPersonMessage __impl, NServiceBus.Unicast.Transport__impl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null;Namespace.Service.ILinkPersonMessage, Namespace.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</Value>
</HeaderInfo>
<HeaderInfo>
<Key>WinIdName</Key>
<Value>*{myusername}*</Value>
</HeaderInfo>
<HeaderInfo>
<Key>CorrId</Key>
</HeaderInfo>
</ArrayOfHeaderInfo>
<><>Update 3
这是目前运作的流层:
Configure.With()
.DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Events"))
.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Messages"))
.CastleWindsorBuilder(container)
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.IsolationLevel(IsolationLevel.ReadUncommitted)
.UnicastBus()
.RavenSagaPersister()
.RavenSubscriptionStorage()
.UseRavenTimeoutPersister()
.RunTimeoutManager()
.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install();
(一) 所有名称空间