简体   繁体   中英

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. Producer has a method that takes Employee as method parameter and creates employee in db.

For SOAP based ws, dot net client will hit WSDL and creates the stubs (including employee data representation in 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. 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?

I know there is WADL(parallel to WSDL) in rest but looks like its not very prominent and not a standard as of now.

I am not getting how client side code will generate EmployeeData class so that it can fill it and send to producer? 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)? Even if client has to do it manually, how client will know what is the class definition of EmployeeData class without wsdl or wadl?

One important concept of REST is HATEOAS or Hypermedia as the Engine of Application State . What this means is that your client interacts with the REST service through hypermedia links that the service hands it.

Your REST web service has an entry point, say http://yourhost.com/rest . Your client will start by sending the request to that 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).

Here's an awesome video describing this concept: Hypermedia APIs.

Through HATEOAS you can make your service API completely discoverable by just following hypermedia links.


There is no concept of top down/bottom up design in REST.

REST is about resources, not about method calls, which is basically what a WSDL describes.

Even if client has to do it manually, how client will know what is the class definition of EmployeeData class without wsdl or wadl?

It won't need to create an EmployeeData class. 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. That might be an XHTML response like so (among other things)

<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. This is HATEOAS. The hypermedia link is the /context/employees . The engine is following this link with a PUT request. 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:

  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/
  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.
  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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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