在java中使用SOAP webservice,只有WSDL在手
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25920799/
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
Consume SOAP webservice in java, only WSDL in hand
提问by Riju Mahna
I need to consume a web service in java/jsp code. Only the WSDL is available for me to start.
我需要在 java/jsp 代码中使用 Web 服务。只有 WSDL 可供我开始。
I understand I need to convert the WSDL into java client JAR file using AXIS2 / CXF but I cannot build the whole application on this.
我知道我需要使用 AXIS2/CXF 将 WSDL 转换为 java 客户端 JAR 文件,但我无法在此基础上构建整个应用程序。
Can someone provide a simple example or basic steps for me to start on this?
有人可以提供一个简单的示例或基本步骤让我开始吗?
I am not able to join the dots here. WSDL, java client JAR, AXIS2.... All online tutorials point on 'creating' a web service.
我无法在这里加入这些点。WSDL、Java 客户端 JAR、AXIS2……所有在线教程都指向“创建”Web 服务。
采纳答案by oardic
WSDL is just the conract for the web service. You need to generate client code using it, later you can implement your code to call the web service. Like @maerics pointed out, you should use wsdl2java to generate your client code for AXIS2 and use your client to consume the web service.
WSDL 只是 Web 服务的契约。您需要使用它生成客户端代码,稍后您可以实现您的代码来调用 Web 服务。就像@maerics 指出的那样,您应该使用 wsdl2java 为 AXIS2 生成您的客户端代码,并使用您的客户端来使用 Web 服务。
You can check this linkfor an example of client stub generation for AXIS2.
您可以查看此链接以获取 AXIS2 的客户端存根生成示例。
回答by sumitsu
There are a number of tools capable of doing this included in various frameworks and app servers (CXF, JBoss/Wildfly, etc.), but the JDK itself includes a tool called wsimport
which can consume a WSDL file and produce the JAX-WS stubs you need to remotely-invoke the service endpoints via a Java client.
各种框架和应用程序服务器(CXF、JBoss/Wildfly 等)中包含许多能够执行此操作的工具,但 JDK 本身包含一个名为的工具wsimport
,该工具可以使用 WSDL 文件并生成您需要的 JAX-WS 存根需要通过 Java 客户端远程调用服务端点。
Here's one quick description: http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/; here is the Oracle documentation for the tool in JDK 7: http://docs.oracle.com/javase/7/docs/technotes/tools/share/wsimport.html.
这是一个快速描述:http: //www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/;这是 JDK 7 中该工具的 Oracle 文档:http: //docs.oracle.com/javase/7/docs/technotes/tools/share/wsimport.html。