1

I'm implementing new REST API method which allows calling other REST API methods in batch\bulk manner. Similar to Facebook's https://developers.facebook.com/docs/graph-api/making-multiple-requests

Request example:

POST /batch
[
  {"method":"GET", "relative_url":"/user/anton"},
  {"method":"GET", "relative_url":"/user/vitaliy"}
  {"method":"POST", "relative_url":"/user/dan", "body":{name:Dan}}
]

Response example:

status 200
[
  {"status":"200", "body":{name:"Dan"}},
  {"status":"404"},
  {"status":"201"}
]

In short, batch method should on server-side call OTHER methods one-by-one and return result as array of results.

The most simple solution will be create .Net HttpClient on server side and call other WCF methods on-by-one.

The question is: How implement this using WCF infrastructure without calling WCF method externally via HttpClient?

The reason for that - I don't want to have network-round trips. The most perfect solution will be to use .Net Reflection, but this not good solution in terms of REST abstraction

The most close solution is create WCF Message including HttpRequestMessageProperty (URL, Headers, Method, Content-Type) and send it to processing by WCF infrastructure (just it was sent via HTTP protocol) (not sure about this):

Message responseMessage = wcfInsfrastucture.Process(createWcfMessage(url, method,contentType,body));

Currently I'm lost in WCF Samples, and WCF server-side channel architecture. Most similar question was asked in Sending custom WCF Message to a service but I can't making it work with existing configured server-side behaviors.

Similar questions:

Community
  • 1
  • 1
vitrilo
  • 1,437
  • 16
  • 20

1 Answers1

0

How implement this using WCF infrastructure without calling WCF method externally via HttpClient?

The only way I found is to implement request-response pattern over WCF.

  1. Create a single entry point in WCF service, that receives an abstract request as an argument and returns an abstract response.

For example,

<OperationContract> function Execute(Request as IRequest) as IResponse
  1. Create concrete request and response classes for service operations

  2. Create CompositeRequest and CompositeResponse for Batch / Bulk operations

All service has to do is to apply business logic according to request type.

In case service receives CompositeRequest it just calls the same Execute method for all nested requests one-by-one and aggregates responses into CompositeResponse.

Community
  • 1
  • 1
Lightman
  • 1,078
  • 11
  • 22