NServiceBus Bus.Send (). Registration (callback) Does not work on IIS / Windows Server 2008

I struggled with this problem for several days, and I just can't figure out how to do this.

I have a simple WCF web service hosted on IIS and Windows Server 2008 R2. The web service implementation is as follows:

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; 

I know that trying to use NSB synchronously is considered a bad design, but I'm just experimenting, and I'd really like it to work. Therefore, the problem is that the message is successfully sent to the remote endpoint, and the message is processed successfully, but the response message is simply lost on the air when the remote endpoint does Bus.Reply. I am using the latest version of NSB, and it is strange that this works fine on my Windows 7 development machine. I made sure that the active directory is disabled on both machines. I also ran Wireshark on the receiving endpoint, and I'm sure that I see the incoming message in the packet data. Something does not seem to be alive with IIS. I also switched the registration threshold to DEBUG for both endpoints, and nothing unusual happens. The sending endpoint says the usual "sending messages to ..." Here is the code in my Application_Startup for the web component:

  Bus = NServiceBus.Configure.WithWeb() .Log4Net() .DefaultBuilder() .XmlSerializer() .MsmqTransport() .IsTransactional(false) .PurgeOnStartup(false) .UnicastBus() .ImpersonateSender(false) .CreateBus() .Start(); 

Here are the configurations for the endpoints:

 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" /> 

I also created two standalone NServiceBusHost applications to test communications, and it worked successfully. I also hardcoded the return address and replaced .Reply with .Send, but specifying the actual destination and it still doesn't work. So again, this is due to IIS. Any help would be greatly appreciated!

+4
source share
2 answers

I solved the problem. It turns out that the reason the answers are lost is due to the fact that I referred to the distributor as such:

 <UnicastBusConfig DistributorControlAddress=" Node.Distributor.ControlInputQueue@10.1.4.58 " DistributorDataAddress=" Node.Distributor.DataInputQueue@10.1.4.58 " /> 

But it turns out that the NServiceBus distributor does not like IP addresses. So I changed it to the following:

 <UnicastBusConfig DistributorControlAddress=" Node.Distributor.ControlInputQueue@HOSTNAME " DistributorDataAddress=" Node.Distributor.DataInputQueue@HOSTNAME " /> 

and this solved the problem. I also had to update my hosts file on Windows, since NSB / MSMQ uses hostnames. I am not sure if this is an error in NServiceBus, or if it is a known issue, but it should really be documented if it has not already been.

+1
source

It looks like access rights to the queue. Check your queues on the WCF side to see if msmq can even deliver a message

0
source

Source: https://habr.com/ru/post/1393112/


All Articles