REST Web 服务 WSDL?
我正在实现一个 Web 服务,并且已经实现了 REST 和 SOAP 版本,看看哪个版本适合我的需求。我决定选择 REST,因为它很简单,而且我可能会开发一个 iPhone 应用程序来使用它。我的问题很简单,是否可以为我的 REST 服务创建 WSDL 或 WADL?有必要吗?
谢谢
I am implementing a web service and I have implemented both a REST and SOAP version to see which suited my needs.I have decided to choose REST because of its simplicity and that I will probably be developing an iPhone app to consume it. My question is simple really, is it possible to create a WSDL or WADL for my REST service and is it necessary?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
有了良好的 RESTful 服务,就没有必要为其生成 WADL(更不用说不太合适的 WSDL)了,因为它会自我描述。我所说的“自我描述”具体是指它将提供描述服务发布的所有(相关)资源的文档,并且对其中任何资源使用标准 HTTP OPTIONS 请求将生成有关如何交互的基本信息。使用 WADL 的唯一真正好处是它允许调用者提前发现需要处理的复杂文档的模式; REST 本身并没有提供任何帮助(一些 RESTians 认为这样做会适得其反,我不确定我是否同意)。
当然,这并没有捕获更深层的交互模式,但绝大多数服务的 WSDL 描述也没有捕获到,因此没有任何变化。
作为记录,我使用 Apache CXF 创建 RESTful 服务(使用 JAX-RS)并为它们发布 WADL。
With a good RESTful service, it's not necessary to generate WADL (let alone the much-less-well-fitting WSDL) for it because it will self-describe. By “self-describe” I specifically mean that it will deliver documents describing all the (relevant) resources published by the service, and that using a standard HTTP OPTIONS request on any of these will produce basic information about how to interact. The only real benefit to using WADL is that it allows the caller to discover the schemas for the complex documents it needs to work with ahead of time; REST itself provides no help there (and some RESTians believe that doing such things is counter-productive, which I'm not sure I agree with).
Of course, that doesn't capture the deeper interaction patterns, but neither do the vast majority of WSDL descriptions of services so no change there.
For the record, I use Apache CXF to create RESTful services (using JAX-RS) and that publishes WADL for them.
W3C 已正式建议 REST 文档标准基于 [WSDL 2.0][3]。以下是 IBM 文章中的引用:
The W3C has made a formal recommendation for a REST documentation standard based on [WSDL 2.0][3]. Here is a quote from the IBM article:
正如 @GiuliaDiFederico 所说,“当然这是可能的”(使用 WSDL2),显示了关于如何操作的良好源链接。另一方面,@DonalFellows 并不鼓励使用 WSDL...
我认为 WSDL 的使用是一个问题
As @GiuliaDiFederico said, "of course it's possible" (with WSDL2), showing a good source link about how to do. @DonalFellows, by other hand, does not encouraged the use of WSDL...
I think the use of WSDL is a question of
RestDoc 尝试为 REST 资源创建一个简单的文档框架。
可以通过restdoc-renderer使用浏览器。
它还提供 Java 注释启用 RestDoc 文档的即时创建。实现可用于 Jersey 1.x 和 JAX-RS 2.0。
RestDoc tries to create a simple documentation framework for REST resources.
A browser is available via restdoc-renderer.
It also offers Java annotations to enable on-the-fly creation of RestDoc documetnation. Implementations are available for Jersey 1.x and JAX-RS 2.0.
当然有可能,但是为了回答是否有必要,您没有提供足够的信息。
我建议您查看 ibm 的developerworks 网站,该网站提供了一个有趣的 关于主题的文章
严格来说,使用 WSDL 1.0 您不能,但是使用 WSDL2 就可以,因为它就是为了接受这种需求而开发的,
Of course it's possible, but for answer if it is necessary or not, you didn't provide enough info.
I suggest you to take a look on the ibm's developerworks site that provide an interesting article on subject
Strictly, with WSDL 1.0 you can' t, but with WSDL2 you can, because was developed for accept this kind of demand,
我认为 WSDL 不适合 REST,WADL 也没有必要。 HTTP 已经公开了 WADL 可以在单独的文件中描述的内容。例如,“Allow”标头返回允许的 HTTP 方法,而内容协商用于选择正确的格式。
I think WSDL is not appropriate for REST and WADL is not necessary. HTTP exposes already what WADL could describe in a separate file. For example the "Allow" header returns allowed HTTP method, and Content Negotiation is for choosing the right format.
WADL 不是必需的。但是,如果应用程序中已存在客户端代码,并且您想要进行新的其余调用,那么最好使用 wadl 生成客户端 java 存根 (POJO)。通过这种方式,客户端 POJO 将与服务端 POJO 同步。例如,如果您要在现有应用程序中用 Rest 服务调用替换 EJB/SOAP 服务调用,那么使用 WADL 是非常安全且良好的做法。
您可以使用 wadl2java maven 插件从 WADL 生成客户端 java 存根。
WADL is not necessary. But, If Client side code is already present in an application and you want to make a new rest call then it is good practice that you use wadl for generating the client side java stub(POJO). By this way, client side POJOs will be in sync with service side POJOs. For example, If you are replacing EJB/SOAP service call with Rest service call in an existing application then It is very safe and good practice to use WADL.
You can generate client side java stubs from WADL by using wadl2java maven plugin.