简体   繁体   English

什么是RESTDL WS中的WSDL等价物。 如果没有,消费者如何生成所需的客户端类?

[英]What is WSDL equivalent in restful WS . If nothing,how consumer generates required client side classes?

Say ,i have producer in java and consumer in dot net. 说,我在java网络中有生产者,在dot网络中有消费者。 Producer has a method that takes Employee as method parameter and creates employee in db. Producer有一个方法,它将Employee作为方法参数并在db中创建employee。

For SOAP based ws, dot net client will hit WSDL and creates the stubs (including employee data representation in dot net). 对于基于SOAP的ws,dot net client将命中WSDL并创建存根(包括dot net中的员工数据表示)。 Now it can fill the object and send to producer. 现在它可以填充对象并发送给制作人。

I am not sure how it will work in restful webservices as there is no WSDL. 我不确定它在restful webservices中是如何工作的,因为没有WSDL。 How rest consumer will get to know what are the operations exposed by producer without any WSDL contract and how dot net consumer will get stubs (like employee data object) so that it can simply fill it and send across? 休息用户如何知道生产者在没有任何WSDL合同的情况下暴露的操作,以及dot net consumer将如何获得存根(如员工数据对象)以便它可以简单地填充并发送?

I know there is WADL(parallel to WSDL) in rest but looks like its not very prominent and not a standard as of now. 我知道在休息时有WADL(与WSDL并行),但看起来不是很突出,而且现在还不是标准。

I am not getting how client side code will generate EmployeeData class so that it can fill it and send to producer? 我没有得到客户端代码将如何生成EmployeeData类,以便它可以填充它并发送给生产者? Will client manually create extra class (instead of proxy EmployeeData that used to be generated on the basis of WSDL using utilities available at client side)? 客户端是否会手动创建额外的类(而不是使用客户端可用的实用程序在WSDL的基础上生成的代理EmployeeData)? Even if client has to do it manually, how client will know what is the class definition of EmployeeData class without wsdl or wadl? 即使客户端必须手动完成,客户端如何知道没有wsdl或wadl的EmployeeData类的类定义是什么?

One important concept of REST is HATEOAS or Hypermedia as the Engine of Application State . REST的一个重要概念是HATEOAS或Hypermedia作为应用程序状态的引擎 What this means is that your client interacts with the REST service through hypermedia links that the service hands it. 这意味着您的客户端通过服务提供的超媒体链接与REST服务进行交互。

Your REST web service has an entry point, say http://yourhost.com/rest . 您的REST Web服务有一个入口点,比如http://yourhost.com/rest Your client will start by sending the request to that URL. 您的客户端将首先将请求发送到该URL。 Your service will respond with a resource that describes some or all the accessible resources and how to access them. 您的服务将使用描述部分或全部可访问资源以及如何访问它们的资源进行响应。 You keep discovering and following links. 您不断发现并关注链接。 This is how the API is published (and discovered). 这就是API的发布(和发现)的方式。

Here's an awesome video describing this concept: Hypermedia APIs. 这是一个描述这个概念的精彩视频: 超媒体API。

Through HATEOAS you can make your service API completely discoverable by just following hypermedia links. 通过HATEOAS,您只需按照超媒体链接即可完全发现您的服务API。


There is no concept of top down/bottom up design in REST. REST中没有自顶向下/自底向上设计的概念。

REST is about resources, not about method calls, which is basically what a WSDL describes. REST是关于资源的,而不是关于方法调用的,这基本上是WSDL描述的内容。

Even if client has to do it manually, how client will know what is the class definition of EmployeeData class without wsdl or wadl? 即使客户端必须手动完成,客户端如何知道没有wsdl或wadl的EmployeeData类的类定义是什么?

It won't need to create an EmployeeData class. 不需要创建EmployeeData类。 Say you needed to create a new Employee , you would send a GET request to /employees which would possibly return a response containing how to do that. 假设您需要创建一个新的Employee ,您将向/employees发送一个GET请求,该请求可能会返回包含如何执行此操作的响应。 That might be an XHTML response like so (among other things) 这可能是像这样的XHTML响应(除其他外)

<form class="new-employee" action="/context/employees" method="PUT" >
    <input type="text" name="employee_name" />
    <input type="text" name="employee_age" />
    <input type="submit" name="submit" />
</form>

The response contains the exact format you need to follow to create a new employee. 响应包含创建新员工时需要遵循的确切格式。 You need to submit the form to /context/employees with an HTTP PUT request containing those form parameters. 您需要使用包含这些表单参数的HTTP PUT请求将表单提交给/context/employees This is HATEOAS. 这是HATEOAS。 The hypermedia link is the /context/employees . 超媒体链接是/context/employees The engine is following this link with a PUT request. 引擎通过PUT请求跟随此链接。 The application state is that after this request, a new employee will exist. 应用程序状态是在此请求之后,将存在新员工。

Assuming that you're using the Json based WS - there is some tools that helps: 假设您正在使用基于Json的WS - 有一些工具可以帮助:

  1. there are json parsers that can turn json, or json schema files into POJO classes, and put some annotations used by Json parsing libraries - take a look here: http://www.jsonschema2pojo.org/ 有json解析器,可以将json或json模式文件转换为POJO类,并放入Json解析库使用的一些注释 - 请看这里: http//www.jsonschema2pojo.org/
  2. I don't know any automated tool that can generate server stub in terms of all API calls etc. but there is a nice library to consume it - https://github.com/square/retrofit - you have to still put patches and methods signatures into interfase, but it's a way more convinient that playing with "pure" java. 我不知道任何可以根据所有API调用生成服务器存根的自动化工具,但是有一个很好的库可以使用它 - https://github.com/square/retrofit - 你必须仍然放置补丁和方法签名到interfase,但它更方便玩“纯”java。
  3. There are also some quite nice tools helping to generate and format documentation for WS - one I like most is swagger: https://helloreverb.com/developers/swagger 还有一些非常好的工具可以帮助生成和格式化WS的文档 - 我最喜欢的是swagger: https//helloreverb.com/developers/swagger

There is no (or at least I don't know about it) tool that allow to generate stub, data classes etc. as it can ve usually done with WSDL file. 没有(或者至少我不知道)工具允许生成存根,数据类等,因为它通常可以通过WSDL文件完成。

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

相关问题 RESTful WS-Jersey-客户端解组问题 - RESTful WS - Jersey - client side unmarshalling issue 如何检查通过RESTful客户端(javax.ws.rs.client)发送到restful webservice的exacly请求 - how to check what exacly request i send to restful webservice via restful client (javax.ws.rs.client) Generated sources from WSDL using WSDL2Java generates classes with deprecated API javax xml ws on java 11 - Generated sources from WSDL using WSDL2Java generates classes with deprecated API javax xml ws on java 11 Spring-WS生成WSDL而不进行操作 - Spring-WS generates WSDL without operations 是否需要生成java类才能使用spring-ws客户端 - Is it required to generate java classes to use spring-ws client 如何从Netbeans中的WSDL创建SOAP WS Client(带有身份验证) - How to Create SOAP WS Client (with authentication) from WSDL in Netbeans 如何在JAVA中为WSDL中定义的REST生成RESTful客户端 - How to generate RESTful client in JAVA for REST defined in WSDL 当WSDL太大时,JAX-WS客户端挂起30秒 - JAX-WS client side is hanging for 30 secs when WSDL is too large 使用 Tomcat 创建 Restful Client Consumer - Create Restful Client Consumer with Tomcat JAX-WS 客户端:访问本地 WSDL 的正确路径是什么? - JAX-WS client : what's the correct path to access the local WSDL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM