创建基于 Java 的 Web 服务
我有一个非常基本的基于 Java 的 Web 服务需求。需求很简单,传递一些字符串参数,将它们保存到数据库并生成响应(“成功”,“失败”)。还有一种情况,我需要返回一个简单对象的简单 XML 表示(SOAP 消息):
<person>
<name>the name</name>
<address>the name</address>
......
</person>
我们当前的环境是 Windows、Apache Tomcat 5、SQL Server。 我是网络服务新手,所以我正在尝试找出可以使用哪些技术来完成这项工作。例如:
我真的需要 Apache Axis 2 来实现这个功能吗?它会不会太过分?
我在网上看到一个教程,其中创建 Web 服务所需的只是 Eclipse、Eclipse 的 Lomboz 插件和 Apache Tomcat。如果我选择这条路线,我还需要 Apache Axis2 吗?
Tomcat 是否可以处理 Web 服务请求消息或者我是否需要第三方库?
我想我正在寻找最简单的方法来实现这一点。谢谢。
I have a very basic Java based web service requirement. Requirement is very simple, pass some String parameters, save them to database and generate a response ("success", "failed"). There is also a case where I need to return simple XML representation (SOAP message) of a simple Object:
<person>
<name>the name</name>
<address>the name</address>
......
</person>
Our current environment is Windows, Apache Tomcat 5, SQL Server.
I'm new to web services so I'm trying to figure out what technologies I could use to make this work. For example:
Do I really need Apache Axis 2 to implement this or would it be overkill?
I saw a tutorial online where all that was needed to create web service was Eclipse, Lomboz plugin for Eclipse and Apache Tomcat. Will I still need Apache Axis2 if I take this route?
Is it possible for Tomcat to process web service requests messages or do I need third party libraries?
I guess I'm looking for the easiest way to implement this. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您真的需要 SOAP 支持吗?如果您这样做,安讯士可能是您最好的选择。否则,我会看看 Jersey。
Do you actually need SOAP support? If you do, Axis is probably your best bet. Otherwise, I'd take a look at Jersey.
如果它像您提到的那么简单,为什么不看看 RESTful Web 服务?您可以通过 GET、POST、DELETE 或 PUT HTTP 方法指定资源调用。
有一个关于如何实现此目标的博客教程。它还向您展示了如何返回 JSON 字符串/XML(取决于您想要的)。
If it will be as simple as you have mentioned, why don't you look at RESTful Web Services? You can specify your resource calls through a GET, POST, DELETE or PUT HTTP methods.
There's a blog tutorial on how to achieve this. It also shows you how you can return JSON strings/XML (depending on what you want).
Web 框架将使这变得更加容易(并且实际上是可维护的),但您可以只编写一个原始 servlet 来处理请求。不过,您需要使用 XML 对象序列化方法,或者至少使用 xml解析库。
A web framework would make this much easier (and actually maintainable), but you could just write a raw servlet to handle requests. You'll want to use an XML object serialization method, though, or at the very least an xml parsing library.
我想你需要这个轴。但如果将来您需要 Web 服务应用程序的更多支持,我会建议您查看 Apache CXF。 CXF 就像 axis2 一样是 jax-ws 的实现,但具有支持 jax-rs (其余)的优点。这意味着您可以公开 REST 和 SOAP Web 服务接口。
I think you would need axis for this one. But I'll advice you to look at Apache CXF, if in future you will need more support with web service apps. CXF just like axis2 is an implimentation of jax-ws but with an advantage of supporting jax-rs (rest). This means you can expose both REST and SOAP web service interfaces.