我已经为这个问题苦苦挣扎了几天,但我似乎无法弄清楚。
我有一个托管在 IIS 和 Windows Server 2008 R2 上的简单 WCF Web 服务。 Web Service的实现如下:
var completionResult = new CompletionResult();
var updateTextMessage = new UpdateText { TextTemplateId = textTemplateId, Text = text };
var asyncResult = Global.Bus.Send(updateTextMessage).Register(x => completionResult = x.AsyncState as CompletionResult, null);
asyncResult.AsyncWaitHandle.WaitOne(10000);
if (completionResult.Messages != null && completionResult.Messages.Length > 0)
{
return ((UpdateTextResponse)completionResult.Messages[0]).ImageData;
}
return string.Empty;
我知道尝试以同步方式使用 NSB 被认为是糟糕的设计,但我只是在尝试,我真的很想让它发挥作用。因此,问题在于消息已成功发送到远程端点并且消息已成功处理,但当远程端点执行 Bus.Reply 时,回复消息只是在以太中丢失。我正在使用最新版本的 NSB,奇怪的是它在我的 Windows 7 开发机器上运行良好。我已确保两台计算机上的活动目录均已关闭。我还在接收端点上运行了 Wireshark,果然我在数据包数据中看到了传入消息。似乎有些东西与 IIS 不兼容。我还将两个端点的日志记录阈值都切换为“调试”,没有发生任何异常情况。发送端点通常会说“将消息发送到...”,这是我的 Application_Startup 中 Web 组件的代码:
Bus = NServiceBus.Configure.WithWeb()
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(false)
.PurgeOnStartup(false)
.UnicastBus()
.ImpersonateSender(false)
.CreateBus()
.Start();
以下是端点的配置:
IIS Config (this side is not getting the response)
<MsmqTransportConfig InputQueue="Web.InputQueue" ErrorQueue="Web.ErrorQueue" MaxRetries="5" NumberOfWorkerThreads="1"/>
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Messages" Endpoint="Node.Distributor.DataInputQueue"/>
</MessageEndpointMappings>
</UnicastBusConfig>
---------------------------------------------------------------
Endpoint which does the reply
<MsmqTransportConfig ErrorQueue="Node.ErrorQueue" InputQueue="Node.InputQueue" MaxRetries="5" NumberOfWorkerThreads="1"/>
<UnicastBusConfig DistributorControlAddress="Node.Distributor.ControlInputQueue" DistributorDataAddress="Node.Distributor.DataInputQueue" />
我还创建了两个独立的 NServiceBusHost 应用程序来测试通信,并且它工作成功。我还对返回地址进行了硬编码,并将 .Reply 替换为 .Send,但指定了实际目的地,但它仍然不起作用。看来又和IIS有关了。任何帮助将不胜感激!