tags:

views:

51

answers:

2

Hi ,

I am using request reply model of NServiceBUs for one of my project.There is a self hosted service bus listening for a request message and reply back with a request message. So in WCF message code i have coded like

// sent the message to bus.
var synchronousMessageSent = 
    this._bus.Send(destinationQueueName, requestMessage)
    .Register(
        (AsyncCallback)delegate(IAsyncResult ar)
        {
             // process the response from the message.
             NServiceBus.CompletionResult completionResult = ar.AsyncState as NServiceBus.CompletionResult;
             if (completionResult != null)
             {
                 // set the response messages.
                 response = completionResult.Messages;
             }                                                     
        }, 
        null);

       // block the current thread.
        synchronousMessageSent.AsyncWaitHandle.WaitOne(1000);
       return response;

The destinaton que will sent the reply. I am getting the resault one or tweo times afetr that the reply is not coming to the client. Am i doing anything wrong

A: 

Why are you trying to turn an a-synchronous framework into a synchronous one? There is a fundamental flaw with what you are trying to do.

You should take a long hard look at your design and appreciate the benefits of a-sync calls. The fact that you are doing

// block the current thread.
synchronousMessageSent.AsyncWaitHandle.WaitOne(1000);

Is highly concerning. What are you trying to achieve with this? Design your system based on a-synchronous messaging communication and you will have a MUCH better system. Otherwise you might as well just use some kind of blocking tcp/ip sockets.

mrnye
A: 

I am having a service resonsible checking whether a partcicular entity exist from wcf call and i need to sent the result back to the caller.If i use synchronous how can i return the reques back?

Ajai