使用 Maven 来自 WSDL 的简单(独立)Java SOAP Web 服务客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/373350/
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
Simple (standalone) Java SOAP web service client from WSDL using Maven
提问by
I'm looking to generate a simple standalone Java client which will make calls to a SOAP web service, given a wsdl. When I say simple and standalone I mean that once I'm done I want to be able to do something like
我希望生成一个简单的独立 Java 客户端,该客户端将调用 SOAP Web 服务,给定 wsdl。当我说简单和独立时,我的意思是一旦我完成,我希望能够做类似的事情
import my.generated.nonsense;
public static void main(String[] args) {
Client client = new Client();
client.getSomething();
}
I've had great time recently with Maven on some other projects and I want to keep that going, so would aim to use it here. I don't want the tool to generate anything expect the classes that allow me to do the above.
我最近在 Maven 的其他一些项目中度过了愉快的时光,我想保持这种状态,所以打算在这里使用它。除了允许我执行上述操作的类之外,我不希望该工具生成任何内容。
Anyone done this recently and can recommend a ws library and Maven plugin? Thanks.
最近有人做过这个并且可以推荐一个 ws 库和 Maven 插件吗?谢谢。
回答by neesh
I would recommend SOAP UIfor what you need to do. You do not need to write any code - you can call the web service from the soap UI client.
我会为您需要做的事情推荐SOAP UI。您不需要编写任何代码——您可以从soap UI 客户端调用Web 服务。
If you need to automate making soap calls you can use the maven plugin as part of your build/deploy process. More info about the maven plugin here: http://www.soapui.org/Test-Automation/maven-2x.html
如果您需要自动进行soap 调用,您可以使用maven 插件作为构建/部署过程的一部分。有关 Maven 插件的更多信息,请访问:http: //www.soapui.org/Test-Automation/maven-2x.html
回答by kgiannakakis
Have a look at CXF and its Maven plug in. CXF would generate code similar to yours (of course web services could fail and you should add exception handling). Have in mind though that SOAP web services is a complicated topic and simplicity in the generated code may not be always desirable. Generating a client with the default settings may not work for some clients. You would then need to tweak the configuration of the code generation and/or add code to handle it. CXF is good both for easy/default clients and more complicated ones.
看看 CXF 和它的 Maven插件。CXF 会生成与您类似的代码(当然 Web 服务可能会失败,您应该添加异常处理)。请记住,尽管 SOAP Web 服务是一个复杂的主题,并且生成的代码中的简单性可能并不总是可取的。使用默认设置生成客户端可能不适用于某些客户端。然后,您需要调整代码生成的配置和/或添加代码来处理它。CXF 既适用于简单/默认客户端,也适用于更复杂的客户端。