Data transfered as parameter or as result
I want data to be transfered from point A to point B. I have web services in A and in B. Which desig开发者_运维技巧n is better?
- A.GetData() :hosted in A, returns data, will be called from B
- B.TakeData(Data pData) :hosted in B, Data passed as parameter, will be called from A
Why approach 1 or 2 is the best way?
You would want to implement Pull GetData()
or Push TakeData()
based on how would problem/solution look like in the real world business problem. Very crude example is while implementing a fire alarm
I would make it push so that I push that information to all the people in the building even if they are not expecting(polling
) it here TakeData()
is more suitable. If I want to implement GetEmployeeSalary
I seldom need to blast this information to all the subscribers, since it is sensitive/confidential information I'd want to provide to the people who are asking for it, that too after verifying they are allowed to do so here GetData()
makes more sense.
I dont know about the technology you are using, but there should be mechanisms to implement either a push or pull model(atleast WCF has these WS-Eventing).
When Push - Ideally when there is a real world need to update multiple systems/clients with an update. Imagine a stock ticker webservice, and each client is interested in different quotes. It might make sense to send push notifications to the paid clients on every change, about the ticker each client is interested in, while only allowing pull like GetData()
with delayed data for free clients.
- Use push when you see polling (polling is wastage of resources)
- Prefer push when there is distributed processing requirement on events in Webservices.
精彩评论