NServiceBus在EnclosedMessageTypes元数据中使用类型全名

时间:2015-05-08 14:09:51

标签: serialization nservicebus assembly-signing

NServiceBus包括带有消息" NServiceBus.EnclosedMessageTypes"的元标题。 它将序列化类型的AssemblyQualifiedName放在那里。

例如:MyNamespance.MyType, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7777777777777777

我可以使用NServiceBus来代替FullName吗?

例如:MyNamespance.MyType而不是AssemblyQualifiedName。

用例: 系统代码的一些遗留部分需要签署程序集。出于这个原因,我不想签署所有程序集。因此,黑客程序集只能在遗留应用程序中自签名。但是,当遗留应用程序NServiceBus中序列化的共享合同包的消息无法在没有签名程序集的情况下反序列化它们时。

'NServiceBus.MessageDeserializationException: An error occurred while attempting to extract logical messages from transport message 99999999-9999-99999-9999-999999999999 ---> Newtonsoft.Json.JsonSerializationException: Type specified in JSON 'MyNamespance.MyType, MyAssembly' was not resolved. Path '[0].$type', line 9, position 999.'

1 个答案:

答案 0 :(得分:2)

答案在<div class="control-group col-md-6"><span title="Required" class="text-danger glyphicon glyphicon-asterisk"></span> <label class="control-label" for="OperatorName">Operator Name</label><span class="field-validation-error" data-valmsg-for="OperatorName" data-valmsg-replace="true"><span class="" for="OperatorName">The Operator Name field is required.</span></span> <div class="controls"> <input aria-invalid="true" aria-required="true" class="form-control input-validation-error" data-val="true" data-val-length="The field Operator Name must be a string with a maximum length of 255." data-val-length-max="255" data-val-required="The Operator Name field is required." id="OperatorName" maxlength="255" name="OperatorName" value="Haley Chisholm and Morris Inc" type="text"> </div> </div>或更具体地说是IMutateTransportMessages

它允许更改标题,因此我可以删除PublicToken,因此程序集看起来没有签名。

IMutateOutgoingTransportMessages

别忘了注册:

public class EnclosedMessageTypeMutator : IMutateOutgoingTransportMessages
{
    public void MutateOutgoing(LogicalMessage logicalMessage, TransportMessage transportMessage)
    {
        var header = transportMessage.Headers["NServiceBus.EnclosedMessageTypes"];
        header = header.Substring(0, header.LastIndexOf("=", StringComparison.InvariantCulture) + 1) + "null";
        transportMessage.Headers["NServiceBus.EnclosedMessageTypes"] = header;
    }
}