I have a bunch of C#.NET/OpenRasta web services that I'm continuously adding to.
When a new service is added it's often the case that it was added because it is required by an application that is already using another of my web services... Some times, it's just the case that there is an apparent synergy between a new service and an existing one that means we may want to call one then call the other on the returned results.
These services live in a single C# Visual studio project (for better or worse, this was not my decision to make).
What I'm looking for is an existing API/library or a pattern or piece of software (or a nudge from some one saying "you know... OpenRasta can do that out-the-box") I could use to allow my service to interact with each other, in a very loose and dynamic fashion, before returning a result.
For example: lets say one of my services is user state/data storage and the other is geo data. An application could pull back a user from the user service, then look his IP up using the geo data service, but this would take 2 service calls from the application.
Or: Say I have a stock data service that supplies me with detailed information about products and a warehouse stock level service that provides me with current stock and re-order amounts, etc. But if I wanted the stocks description and the amount we currently have in stock I would have to make two calls from the application.
What would be nice is if I could get some kind of framework where I can call (something like)..
http://www.foo.com/user?id=8890823123&ip=county:geo|country|fromIp
and my user json object would come back with it's ip address replaced by a field called "country" that was resolved by passing the ip address as a parameter to the /geo/country/fromIp service method. OR if I could call the stock services like:
GET
http://www.bar.com/product
{"desc": "/product?id=92236262", "stock":"/stock?id=92236262"}
and get back a json object that looked like {"desc" : "brown leather shoes, size 9 1/2", "stock": "7"}
I'd really like to be able to do this without hard coding the knowledge of one service into the other; so that when a new service is adde开发者_StackOverflowd any of the existing ones can use it to do look-ups, etc.
Is this something I would need to code myself or do such things exist already?
The OData guys are trying to do the kind of URI composition you are describing. I don't think they actually have an implementation yet.
I don't think it is a good idea, nor necessary but that's just my opinion. If you want to compose resources then create a layer in your architecture that exposes those composed resources explicitly. Doing it via the URI is an open invitation to coupling and performance problems.
精彩评论