2010-01-05 65 views

回答

1

看看AsyncPages示例。如果你希望它是同步的,直到回調完成。

希望這會有所幫助!

1

還可以選擇將NServiceBus端點公開爲Web服務和wcf服務,並且可以按照您的預期同步調用這些服務。

1

客戶端不是aspx頁面,所以我不能像異步樣本一樣使用它。 我使用的是RIA服務,所以我無法控制wcf服務本身的同步化。我使用Wait和Pulse解決了它:

[WebMethod] 
    public string HelloWorld(int number) 
    { 
     string returnVal = "" ; 
     var command = new Command { Id = number }; 
     lock(this) 
     {     
      Global.Bus.Send(command).Register<ErrorCodes>(code => 
       { 
        lock(this) 
        { 
         returnVal = returnVal = Enum.GetName(typeof(ErrorCodes), code); 
         Monitor.Pulse(this); 
        } 
       } 
      ); 

      Monitor.Wait(this);     
     } 
     return returnVal; 
    }