Java 使用 Web 服务时,端点、服务和端口之间有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11561/
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-08-11 07:09:49  来源:igfitidea点击:

What is the difference between an endpoint, a service, and a port when working with webservices?

java.netweb-servicescxfaxis

提问by ScArcher2

I've used Apache CXF to expose about ten java classes as web services.

我已经使用 Apache CXF 将大约十个 Java 类公开为 Web 服务。

I've generated clients using CXF, Axis, and .NET.

我已经使用 CXF、Axis 和 .NET 生成了客户端。

In Axis and CXF a "Service" or "Locator" is generated. From this service you can get a "Port". The "Port" is used to make individual calls to the methods exposed by the web service.

在 Axis 和 CXF 中,会生成“服务”或“定位器”。从此服务中,您可以获得一个“端口”。“端口”用于对 Web 服务公开的方法进行单独调用。

In .NET the "Service" directly exposes the calls to the web service.

在 .NET 中,“服务”直接公开对 Web 服务的调用。

Can someone explain the difference between a port, a service, a locator, and an endpoint when it comes to web services?

有人能解释一下 Web 服务中端口、服务、定位器和端点之间的区别吗?

Axis:

轴:

PatientServiceImplServiceLocator locator = 
    new PatientServiceImplServiceLocator();
PatientService service = locator.getPatientServiceImplPort();

CXF:

CXF:

PatientServiceImplService locator = new PatientServiceImplService();
PatientService service = locator.getPatientServiceImplPort();

.net:

。网:

PatientServiceImplService service = new PatientServiceImplService();

采纳答案by Kev

I'd hop over to http://www.w3.org/TR/wsdl.htmlwhich I think explains Port, Service and Endpoint reasonably well. A locator is an implementation specific mechanism that some WS stacks use to provide access to service endpoints.

我会跳到http://www.w3.org/TR/wsdl.html,我认为它很好地解释了端口、服务和端点。定位器是一种特定于实现的机制,某些 WS 堆栈使用它来提供对服务端点的访问。

回答by Greg Hurlman

As you already mentioned, those terms mean different things in different stacks - there is no one right generic answer for web services.

正如您已经提到的,这些术语在不同的堆栈中意味着不同的东西 - Web 服务没有一个正确的通用答案。

回答by ScArcher2

I found the information based on Kevin Kenny's answer, but I figured I'd post it here for others.

我根据凯文肯尼的回答找到了信息,但我想我会在这里发布给其他人。

A WSDL document defines services as collections of network endpoints, or ports. In WSDL, the abstract definition of endpoints and messages is separated from their concrete network deployment or data format bindings. This allows the reuse of abstract definitions: messages, which are abstract descriptions of the data being exchanged, and port types which are abstract collections of operations. The concrete protocol and data format specifications for a particular port type constitutes a reusable binding. A port is defined by associating a network address with a reusable binding, and a collection of ports define a service. Hence, a WSDL document uses the following elements in the definition of network services:

WSDL 文档将服务定义为网络端点或端口的集合。在 WSDL 中,端点和消息的抽象定义与其具体的网络部署或数据格式绑定分开。这允许重用抽象定义:消息,它是正在交换的数据的抽象描述,端口类型是操作的抽象集合。特定端口类型的具体协议和数据格式规范构成了可重用的绑定。端口是通过将网络地址与可重用绑定相关联来定义的,端口集合定义了服务。因此,WSDL 文档在网络服务的定义中使用以下元素:

  • Types– a container for data type definitions using some type system (such as XSD).
  • Message– an abstract, typed definition of the data being communicated.
  • Operation– an abstract description of an action supported by the service.
  • Port Type–an abstract set of operations supported by one or more endpoints.
  • Binding– a concrete protocol and data format specification for a particular port type.
  • Port– a single endpoint defined as a combination of a binding and a network address.
  • Service– a collection of related endpoints.
  • 类型– 使用某种类型系统(例如 XSD)的数据类型定义的容器。
  • 消息– 正在通信的数据的抽象、类型化定义。
  • 操作- 服务支持的操作的抽象描述。
  • 端口类型——由一个或多个端点支持的一组抽象操作。
  • 绑定——特定端口类型的具体协议和数据格式规范。
  • 端口– 定义为绑定和网络地址组合的单个端点。
  • 服务——相关端点的集合。

回答by pHneutre

I would like to add that <port>and <endpoint>serve the same purpose, but portis used by WSDL 1.1 and endpointby WSDL 2.0.

我想添加它<port><endpoint>用于相同的目的,但port被 WSDL 1.1 和endpointWSDL 2.0 使用。