哪个是开发 Web 服务的更好方法?先签约还是后签约?
各自的优点和缺点是什么?
你有哪些经验?
编辑 这个问题是关于 Web 服务的实现(阅读:SOAP)问题是是否应该首先对实现类进行编码,然后生成 WSDL 和 XSD 模式(最后一个合同)或首先编写 WSDL 和 XSD 模式,然后生成的实现类(合约优先)
哪个是开发 Web 服务的更好方法?先签约还是后签约?
各自的优点和缺点是什么?
你有哪些经验?
编辑 这个问题是关于 Web 服务的实现(阅读:SOAP)问题是是否应该首先对实现类进行编码,然后生成 WSDL 和 XSD 模式(最后一个合同)或首先编写 WSDL 和 XSD 模式,然后生成的实现类(合约优先)
合同优先是普遍接受的“最佳实践”。
它使您对服务的生产者和消费者都非常清楚需要什么和期望什么。当您开始尝试转换 java 类型 -> xml 类型时,这一点变得尤为重要。您还可以跨不同的 Web 服务重用模式。
我已经使用了这两种方法。我的建议是使用契约优先模式,但代码优先WSDL。
编写 WSDL 文件有很多奇怪的细微差别,例如绑定、端口等。我宁愿用工具而不是手工完成。有一些工具可以帮助做到这一点,但没有一个比这更简单
@网络服务 上市 ...
至少您可以验证您的部署。
对于模式,我建议先契约,因为 XML Schema 语言比你用 Java 描述的要丰富得多。我通常给出的一个例子是显示 XML Schema 可以限制字符串的大小并应用正则表达式模式。在 Java 和注解中这样做看起来有点混乱。
Another advantage of doing the schema as contract first is the presence of tools to convert your schema file into HTML documentation.
The XJC tool can generate the requisite class files. However, I would only recommend doing that at start.
In the end you should take the generated WSDL file and work with that instead. That way you can use wsimport and verify that the whole thing from WSDL to Schema is valid.
You can deploy with the WSDL file by using the wsdlLocation attribute in your @WebService implementation and the application server will fix the binding data for you when users request the WSDL from the server, but you still retain your annotations. Otherwise your annotations will not appear on the requested WSDL files.
我怀疑答案是肯定的“这取决于”。
问题是,如果你建立和发布你的合同,你就会受到它的约束。这让改变变得更加困难。不是不可能,而是更难。
另一方面,如果您对模式等感到满意,那么弄乱合约比弄乱代码更快。因此您可以在合约中进行一些增量更改。
是不是也有可以从 WSDL 生成代码骨架的工具?我几乎肯定有。如果是这样,您最好将模式设为“代码”项,并从中生成代码。