在服务器内部调用Web服务 [英] Calling web-services internally within the server

查看:149
本文介绍了在服务器内部调用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个web服务getEmployee(),当传递id时,它会获得单个员工的员工详细信息。

I have a web-service getEmployee() which gets the employee detais for a single employee, when an id is passed.

同一个网络服务服务器getEmployeeList(),当部门通过时,它获取整个员工列表。这将获取部门的ID,然后调用getEmployee()服务以获取所有详细信息。

Another web-service on the same server getEmployeeList() which gets the whole list of employees, when a department is passed. This gets the id's for the departments and then calls the getEmployee() service to get all the details.

Web服务getEmployeeList()的响应基本上是一个集合getEmployee()的响应。

The response of the web-service getEmployeeList() is basically a collection of the responses of getEmployee().

我的问题是如何最好地实现它?最好在内部从getEmployeeList()多次调用getEmployee(),或者每次调用getEmployee()的进程方法(getEmployee()中有一个进程方法,它将xml作为输入并返回响应xml )

My question here is how best to implement it? Is it better to call getEmployee() multiple times from getEmployeeList() internally, or to just call the process method of getEmployee() each time ( there is a process method in getEmployee() which takes as input an xml and returns the response xml)

推荐答案

确切的答案取决于你的应用程序的内部结构,但通常我会调用在同一服务器上运行的另一个Web服务API以便为请求提供服务。这将是低效的并且将一个实现与另一个实现联系起来。

The exact answer is going to depend on the internals of your application is structured, but generally I would not invoke another web service API running on the same server in order to service a request. That's going to be inefficient and ties one implementation to another.

如果您需要返回员工列表,您的前端REST层应该从业务中调用方法或中间层检索相关信息,通常以一组域对象的形式。这个中间层负责从持久层或某种类型获取实际数据 - 即从某种数据库中获取正确的员工列表,但确切的实现细节不应该相关。

If you need to return a list of employees, your front-end REST layer should invoke a method from the business or middle layer to retrieve the relevant information, usually in the form of a set of domain objects. This middle layer would be responsible for getting the actual data from a persistence layer or some sort - i.e. getting the proper list of employees from a database of some sort, though that exact implementation detail should not be relevant.

然后可以将这些转换为用于构建对客户端的响应的正确格式 - 即用于XML的JAXB对象。 (您的中间层也可以直接返回这些JAXB对象,但这种方法有利弊)

These can then be converted into the proper format for building the response to the client - i.e. JAXB objects for XML. (Your middle layer could also directly return these JAXB objects, but there are pros/cons of this approach)

这篇关于在服务器内部调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆