简体   繁体   English

Java Web服务Oracle

[英]Java Web Service Oracle

I have a oracle database with a table tha contains user. 我有一个包含用户表的oracle数据库。 I want to create a web service in java to get a user by id. 我想在Java中创建一个Web服务以按ID获取用户。 How i do this? 我该怎么做? I search in the internet but i only get Hello World Tutorials. 我在互联网上搜索,但仅获得Hello World教程。

Thanks 谢谢

I would suggest you use Spring-WS they have a few good tutorials and a few good sample applications that you can modify to meet your needs. 我建议您使用Spring-WS,他们提供了一些不错的教程和一些不错的示例应用程序,您可以对其进行修改以满足您的需求。 You can find out more at : 您可以在以下位置找到更多信息:

http://static.springsource.org/spring-ws/sites/2.0/ http://static.springsource.org/spring-ws/sites/2.0/

You have to do a few different things: 您必须做一些不同的事情:

  1. You should write a simple wsdl to define your web service. 您应该编写一个简单的wsdl来定义您的Web服务。 This may also require you to write some xml schemas. 这可能还需要您编写一些xml模式。 You can find some examples here: http://www.w3.org/2001/03/14-annotated-WSDL-examples.html . 您可以在此处找到一些示例: http : //www.w3.org/2001/03/14-annotated-WSDL-examples.html Remember wsdls are simply a description of the webservice you intend to write. 请记住,wsdl只是您要编写的Web服务的描述。

  2. The next step is actually write the web service. 下一步实际上是编写Web服务。 This requires you to generate objects that will marshall/unmarshall requests and responses. 这要求您生成将封送/取消封送请求和响应的对象。 The SpringWS documentation gives you a few examples how to do that. SpringWS文档为您提供了一些示例。

  3. Finally you need to write the database level calls. 最后,您需要编写数据库级别的调用。

You really have two problems here: 您这里确实有两个问题:

  1. How to query an Oracle database to get records from the user table for a given id. 如何查询Oracle数据库以从用户表中获取给定ID的记录。
  2. How to expose that method to web clients as a web service. 如何将该方法作为Web服务公开给Web客户端。

You don't say whether you want SOAP or REST. 您没有说要使用SOAP还是REST。

I'd recommend Spring for both. 我都推荐Spring。 Its SimpleJdbcTemplate will make task 1 easy; 它的SimpleJdbcTemplate将使任务1变得容易。 Spring web services will make it easy to write a contract first SOAP service. Spring Web服务将使编写合同优先的SOAP服务变得容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM