WCF Router that combines / aggregates many underlying service responses

221 Views Asked by At

I have a WCF Routing service with two underlying services. The thing I want to get working is combining responses from two backend services and returning one aggregated response (which consists of each of two services are called by router).

Each of that two services returns array of strings. For instance, if the first service returns new string[2] { "red", "green" } and the second's result is new string[2] { "table", "chair" }, the whole final response that will go from router back to client is new string[4] { "red", "green", "table", "chair" }.

Thanks in advance!

1

There are 1 best solutions below

4
Gary Wright On

Unless I'm missing something from your question, is the following the sort of thing you are looking for?

Assuming a WCF service method called GetAggregatedResponse:

public string[] GetAggregatedResponse()
{
    string[] service1Response = callService1AndGetResult();
    string[] service2Response = callService2AndGetResult();
    string[] aggregatedResponse = service1Response.Concat(service2Response).ToArray();
    // Or if you would like to remove duplicates from the results:
    // string[] aggregatedResponse = service1Response.Union(service2Response).ToArray();
    return aggregatedResponse;
}