开发者

synchronized message with nservicebus

开发者 https://www.devze.com 2022-12-15 06:28 出处:网络
I have a web service that needs to ma开发者_运维问答ke a call to nservicebus in a synchronized manner.

I have a web service that needs to ma开发者_运维问答ke a call to nservicebus in a synchronized manner. How can this be achieved ?


Take a look at the AsyncPages sample. If you want it to be synchronous just block until the callback completes.

Hope this helps!


There's also the option of exposing an NServiceBus endpoint as a web service and wcf service, and those can be invoked synchronously as you would expect.


The client is not an aspx page so I cannot use it like the async sample. I am using RIA services, so I am in no control of the synhronization of the wcf service itself. I solved it by using Wait and 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;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消