Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOA, Request/Response service layer, accepting and returning a request/response vs an array or requests/responses?

We are implementing a Request/Response Service Layer using WCF, where every request inherits from a base Request class and every response inherits from base Response class.

The service has a single Process method, which accepts a Request and returns a Response.

// Messages contract
public abstract class Request {}
public abstract class Response {}

// Operation contract
Response Process(Request request);

However certain members of our team are of the opinion that instead of the operation contract expecting and returning a single request/response, it should accept and return an array of requests/responses.

// Operation contract
Response[] Process(Request[] requests);

Personally I do not find it correct semantically and in cases where a collection of related requests are required to be processed at once (perhaps in a batch), would consider introducing BatchRequest and a BatchResponse messages.

public class BatchRequest : Request
{
    public Request[] Requests {get;set;}
}
public class BatchResponses : Response
{
    public string BatchReference {get; set;} // for example
    public Response[] Responses {get;set;}
}

To me accepting and returning an array does not seem correct and this is certainly a pattern I've not seen used anywhere. Is there something more wrong with this? If yes, what is it?

Some people feel that accepting/returning arrays would allow us to not have the extra complexity of introducing batch requests (like the one illustrated above), and that you could send a single request in the array anyways.

Thanks

like image 933
SharePoint Newbie Avatar asked Jun 04 '11 10:06

SharePoint Newbie


People also ask

What is the difference between request and response in API?

Focus at Server, Request is message that arrive to server for request something. Response is message that send from server to client for give thing that client what.

What is request and response in server?

In request/response communication mode, one software module sends a request to a second software module and waits for a response. Because the first software module performs the role of the client, and the second, the role of the server, this mode is also referred to as client/server interaction.

What is request response pair?

One way to gather transactions for virtual service creation is to provide request/response pairs. Request/response pairs are also known as RR pairs or R/R pairs. A request/response pair consists of one request file and one or more response files. Multiple response files are applicable to messaging scenarios.


2 Answers

First of all, arrays add unnecessary complexity. Keep it simple (and) stupid.

For instance. How should errors be treated? If request #1 fails, should request #2 and #3 be executed anyway? How should the errors be reported?

What problems do your colleagues want to solve by making all requests arrays? If it's performance, it smells like premature optimization. There are several other ways to improve performance, but do not do anything until it's really necessary.

If it's to free the client instead of waiting for the result, switch to an asynchronous client.

like image 141
jgauffin Avatar answered Sep 19 '22 14:09

jgauffin


I would prefer a single request and response and use the command pattern for batching up multiple actions to be done.

I find SOA to be complicated enough without seeing unexpected patterns cropping up. What would happen if part of the requests fail, do they all roll back, or only the failed ones. Aaarghhh, my head starts to hurt.

like image 28
Peter Tillemans Avatar answered Sep 20 '22 14:09

Peter Tillemans