tags:

views:

289

answers:

3

I have a web service that needs to make a call to nservicebus in a synchronized manner. How can this be achieved ?

A: 

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

Hope this helps!

Andreas
A: 

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.

Udi Dahan
A: 

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;
    }
larserik