2012-07-30 123 views
0

我一直在一個項目,我需要Nservicebus託管在IIS中。 我需要MVC3的網絡應用程序發送消息,nservicebus主機應該處理這個消息 ,然後發送一些消息給web應用程序。NserviceBus託管在IIS問題

異步頁示例http://docs.particular.net/samples/web/asp-mvc-application/ 顯示了一種方法。我可以得到這個工作,但是這並不完全滿足我的要求。我需要一個從處理程序返回的對象,而不僅僅是一個int。

爲了得到這個工作,我已經試過設置IIS下的宿主,在我的Global.asax我有這樣的代碼:

Bus = Configure.WithWeb()     
       .DefineEndpointName("CQRS") 
       .Log4Net()     
       .DefaultBuilder()     
       .DisableTimeoutManager()     
       .XmlSerializer() 
       .MsmqTransport() 
        .IsTransactional(true) 
        .PurgeOnStartup(false) 
        .InMemorySubscriptionStorage() 
       .UnicastBus()    
        .AllowSubscribeToSelf() 
        .ImpersonateSender(false) 
        .LoadMessageHandlers() 
        .CreateBus().Start(); 

我的web.config:

<MessageForwardingInCaseOfFaultConfig ErrorQueue="CQRS.error" /> 
<MsmqTransportConfig NumberOfWorkerThreads="1" MaxRetries="5" /> 

<UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="" TimeoutManagerAddress="CQRS.timeouts"> 
    <MessageEndpointMappings> 
    <add Messages="Nokavision.InvoiceProcessing.CQRS.Messages" Endpoint="CQRS" /> 
    <add Messages="NServiceBus.Scheduling.Messages.ScheduledTask" Endpoint="CQRS" />  
    </MessageEndpointMappings> 
</UnicastBusConfig> 

使用Bus對象發送消息的過程非常完美,消息出現在「cqrs」隊列中。 然而,web應用程序中的處理程序不會觸發。這是代碼:

public class UpdateInkoopFactuurAlgemeenHandler : IHandleMessages<UpdateInkoopFactuurAlgemeenCommand> 
{ 
    public IBus Bus { get; set; } 

    public void Handle(UpdateInkoopFactuurAlgemeenCommand message) 
    { 
     P2PEntities entities = new P2PEntities(); 

     var factuur = (from f in entities.Documenten.OfType<InkoopFactuur>() 
         where f.DocumentId == message.DTO.DocumentId 
         select f).FirstOrDefault(); 

     if (factuur != null) 
     { 
      factuur.FactuurNummer = message.DTO.FactuurNummer; 
      entities.SaveChanges(); 
     } 

     //Bus.Return(new UpdateInkoopFactuurAlgemeenResponse(message.DTO.ClientConnectionId)); 

    } 
} 

我敢肯定,我失去了一些東西在這裏小,但是我在做什麼錯,爲什麼不處理被觸發,而我可以清楚地看到隊列中的消息。 同樣在Bus對象上,我可以看到正在加載的處理程序。

回答

0

好吧,我想我想通了,似乎由NSB創建的隊列沒有IIS用戶的完全訪問權限。我已經爲每個隊列的每個人設置了「完全控制」,並重新啓動了IIS。不知怎的,它似乎現在工作