java 网络服务是如何工作的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4544181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:52:48  来源:igfitidea点击:

How does a webservice work

javaweb-serviceswebservice-client

提问by user314344

I am new to webservices and i want to implement webservices by using java in my eclipse project.

我是 webservices 的新手,我想通过在我的 eclipse 项目中使用 java 来实现 webservices。

So can anyone tel me how to implement and creating a project please

那么任何人都可以告诉我如何实施和创建一个项目

Thanks

谢谢

回答by Forhad

As defined by W3C web service is a software system to support interoperable machine-to-machine interaction over a network. More elaborately a system consumes service from other software system.

根据 W3C 的定义,Web 服务是一种支持通过网络进行可互操作的机器对机器交互的软件系统。更详细地说,一个系统消耗来自其他软件系统的服务。

Web services has two major classes:

Web 服务有两大类:

  • REST compliant
  • arbitrary web service
  • 符合 REST
  • 任意网络服务

To implement web service one need to choose one category on the basis of his/her requirement. Java has bunch APIS to implement web services on both category.

要实现 Web 服务,需要根据他/她的要求选择一种类别。Java 有一堆 APIS 来实现这两个类别的 Web 服务。

Requirements before implementing web service is :

实施网络服务前的要求是:

  • XML
  • WSDL (web service description language)
  • SOAP protocol etc
  • XML
  • WSDL(网络服务描述语言)
  • SOAP 协议等

REST based is bit easy to implement compare to other category. So it's better to start with REST complaint web services.

与其他类别相比,基于 REST 的实现有点容易。所以最好从 REST 投诉 Web 服务开始。

How web service works :

网络服务的工作原理:

WS works as request-response paradigm , there is an entity which will request for some service to it's specific counterpart namely service provider entity. Upon request, service provider will respond with a response message. So there are two message involved hear one Request message (XML)and one Response message (XML). There are bunch of ways to achieve these. Detail can be found at web service architecture

WS 作为请求-响应范式工作,有一个实体会向它的特定对应物(即服务提供者实体)请求某些服务。根据请求,服务提供商将以响应消息进行响应。所以有两个消息涉及听到一个请求消息(XML)和一个响应消息(XML)。有很多方法可以实现这些。详细信息可以在Web 服务架构中找到

Beginner can start with JERSEYjsr311 standard reference implementation to build RESTful web services.

初学者可以从JERSEYjsr311 标准参考实现开始构建 RESTful Web 服务。

Example (jersey specific):

示例(特定于球衣):

Step One : Creating root resources

第一步:创建根资源

// The Java class will be hosted at the URI path "/helloworld"
   @Path("/helloworld")
   public class HelloWorldResource {

       @GET 
       @Produces("text/plain")
      public String getClichedMessage() {
          return "Hello World";
      }
  }

Step Two : Deploying

第二步:部署

public class Main {

  private static URI getBaseURI() {
      return UriBuilder.fromUri("http://localhost/").port(8080).build();
  }

  public static final URI BASE_URI = getBaseURI();

  protected static HttpServer startServer() throws IOException {
      System.out.println("Starting ...");
      ResourceConfig resourceConfig = new PackagesResourceConfig("com.sun.jersey.samples.helloworld.resources");
      return GrizzlyServerFactory.createHttpServer(BASE_URI, resourceConfig);
  }

  public static void main(String[] args) throws IOException {
      HttpServer httpServer = startServer();
      System.out.println(String.format("Jersey app started with WADL available at "
              + "%sapplication.wadl\nTry out %shelloworld\nHit enter to stop it...",
              BASE_URI, BASE_URI));
      System.in.read();
      httpServer.stop();
  }    

}

}

REST REFERENCE - by Roy T . Fielding

休息参考 - 作者 Roy T。菲尔丁

回答by Vadeg

Webservice is some program interface, which uses SOAP protocol for communication. Using soap, you can communicate with any program, no matter on which language it is written.

Webservice 是一些程序接口,它使用 SOAP 协议进行通信。使用soap,您可以与任何程序进行通信,无论它是用哪种语言编写的。

SOAP is an XML-based communication protocol and encoding format for inter-application communication. Originally conceived by Microsoft and Userland software, it has evolved through several generations; the current spec is version, SOAP 1.2, though version 1.1 is more widespread. The W3C's XML Protocol working group is in charge of the specification. SOAP is widely viewed as the backbone to a new generation of cross-platform cross-language distributed computing applications, termed Web Services.

SOAP 是一种基于 XML 的通信协议和编码格式,用于应用程序间通信。最初由 Microsoft 和 Userland 软件构想,经过几代人的发展;当前的规范是 SOAP 1.2 版,但 1.1 版更为广泛。W3C 的 XML 协议工作组负责规范。SOAP 被广泛视为新一代跨平台跨语言分布式计算应用程序(称为 Web 服务)的支柱。

Here is some examples:

下面是一些例子:

Java web services tutorial

Java Web 服务教程

Axis - One of ASF implementations

Axis - ASF 实现之一

CXF (Previously known as "XFire")

CXF(以前称为“XFire”)

回答by Ratna Dinakar

One of the easiest and best ways is to develop webservice using Apache Axis. Eclipse SOA toolkit supports Axis.

最简单和最好的方法之一是使用 Apache Axis 开发 Web 服务。Eclipse SOA 工具包支持 Axis。

More information regarding sample project can be found here!

可以在此处找到有关示例项目的更多信息!

http://onjava.com/pub/a/onjava/2002/06/05/axis.html

http://onjava.com/pub/a/onjava/2002/06/05/axis.html