尝试使用 WCF 发送/接收到 MSMQ 队列时收到以下错误:
“创建消息安全上下文失败,因为在消息中找不到发件人的 SID。无法接收消息。WindowsDomain MsmqAuthenticationMode 需要发件人的 SID。”
这会导致所有消息都失败并因此移动到另一个有害队列。该错误似乎在接收服务上触发。
客户端配置如下:
<netMsmqBinding>
<binding name="OrderServiceMsmqBinding"
durable="true"
exactlyOnce="true"
maxReceivedMessageSize="2147483647"
maxRetryCycles="1"
receiveErrorHandling="Move"
receiveRetryCount="1"
retryCycleDelay="00:0:05"
deadLetterQueue="Custom"
customDeadLetterQueue="net.msmq://localhost/private/Services.DeadOrderListenerService/DeadOrderListenerService.svc"
useMsmqTracing="true">
<security mode="None" />
<readerQuotas maxStringContentLength="2147483647" />
</binding>
</netMsmqBinding>
也:
<client>
<endpoint address="net.msmq://localhost/private/Services.OrderPlacementProviderService/OrderPlacementProviderService.svc" binding="netMsmqBinding" bindingConfiguration="OrderServiceMsmqBinding" contract="Providers.IOrderPlacementService" name="orderingMsmqEndpoint" />
</client>
接收服务的配置大致相同:
<netMsmqBinding>
<binding name="OrderServiceMsmqBinding"
durable="true"
exactlyOnce="true"
maxReceivedMessageSize="2147483647"
maxRetryCycles="1"
receiveErrorHandling="Move"
receiveRetryCount="1"
retryCycleDelay="00:0:05"
deadLetterQueue="Custom" customDeadLetterQueue="net.msmq://localhost/private/Services.DeadOrderListenerService/DeadOrderListenerService.svc"
timeToLive="00:01:00"
useActiveDirectory="false"
useMsmqTracing="true">
<readerQuotas maxStringContentLength="2147483647" />
</binding>
</netMsmqBinding>
和:
<service name="Services.OrderPlacementProviderService" behaviorConfiguration="OrderServiceBehavior">
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" name="MexOrderService" contract="IMetadataExchange" />
<endpoint address="net.msmq://localhost/private/Services.OrderPlacementProviderService/OrderPlacementProviderService.svc" binding="netMsmqBinding" bindingConfiguration="OrderServiceMsmqBinding" contract="Providers.IOrderPlacementService" name="msmqEndpoint" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/Services.OrderPlacementProviderService" />
</baseAddresses>
</host>
</service>
队列未经身份验证,暂时允许所有人访问。此 SID 问题才刚刚开始发生。它始终发生在不同的环境中,所以我认为我配置错误?
更多信息:客户下订单(在队列上),如下所示:
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
_orderPlacementClient.PlaceOrder(basket, transactionRef, user);
scope.Complete();
}
监听服务看起来像:
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void PlaceOrder(BasketDTO basket, string transactionReference, UserDTO user)
{
_log.Info("Order placed: " + transactionReference + " for user " + user.Id);
try
{
_prov.PlaceOrder(basket, transactionReference, user);
}
catch (Exception ex)
{
_log.Error("Error placing order", ex);
}
}