Search code examples
wcfservicebusazureservicebus

WCF or Service Bus Sessions for Request-Response


I am using On-Premise Service Bus 1.1 for communication between processes.

I need to perform request-response methods between end points and need to decide if I will use WCF or the bus (Service Bus Relay for WCF is not currently available for on premise).

  • WCF would be easiest to talk to via a generated client proxy, potential complexity with IIS host (or self host) and versioning of clients calling the service.

  • For Service Bus create two queues per remote service (i.e. userService, userServiceResponse) and then use sessions. Flexible versioning with different commands. Management of these queues could become complex.

  • For my project everything is within the same subnet and if required WCF endpoints could talk directly to one another

To help me decide which technology to use, my questions are:

  1. Where would WCF be used over request-response service bus?

  2. Are there any libraries for Service Bus queues to implement request-response messaging (or any robust code examples)?

  3. If we have multiple publishers on a queue, how would we return a reply to a specific sender? Would we have multiple serviceReponse queues, or can a single return queue be used?


Solution

  • Service Bus messages can have a SessionID unique for that request where the service will receive the message, do something with it and reply with a message that has the same ID in the ReplyToSessionID. This allows the requesting party to receive based on the Session ID like this

    MessageSession sessionReceiver = _queueClient.AcceptMessageSession(_mySessionID,TimeSpan.FromSeconds(5));
    sessionReceiver.Peek();
    

    I think the big question here is Sync vs Async whether you want the requesting party to sit back and wait for a response (WCF) or back later and check if the response is ready yet Service Bus but that is a business decision.

    This link or this MSDN article might help you get started with Req/Rep for SB.