WSDL 使用 - 使用什么工具?
我无法理解如何创建网络服务客户端。 故事是我需要调用网络服务。据我了解,我需要以某种方式使用 Web 服务来获取正确的 Web 服务类。
我研究了很多方法来做到这一点。例如,我尝试使用脚本使用它们,然后导入类。
然而,我的一位同事建议我尝试使用 Maven 插件 wsdl2code 因为我们已经使用了 Maven-2 。这样做有效,但据我所知会创建很多垃圾文件。我已将以下内容添加到我的 pom.xml 文件中:
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>ws.client.test</packageName>
<wsdlFile>http://localhost:8088/test?WSDL</wsdlFile>
<databindingName>xmlbeans</databindingName>
<outputDirectory>target/ws/test</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
这成功创建了文件,但如上所述,还有很多垃圾文件( xmlsoap/schemas/soap/encoding/...) 或至少比我尝试过的其他 WSDLconsume 更多无用的文件(据我所知)。
问题
是否有通用指南 使用网络服务?自 WSDL 文件是外部的也可能是 改变,因此我想 这样做可能很好 自动在 Maven 中(尽管有 如果 WSDL 突然改变了...)。
如果 wsdl2code 是一个不错的选择,那么所有文件都应该始终在目标目录中创建吗
执行 mvn clean 时它们将被删除)?还有其他更适合的工具吗?
更新/编辑
通过使用例如 JAX-WS wsimport,我得到了我想要的生成文件。 但是,通过在 /target-folder 中创建这些文件,我希望在同一项目中访问它们以实际调用 Web 服务。这可能吗?
I'm having trouble understanding how to make a web service client.
The story is that I need to make a call to a web service. As I then understand it I need to somehow consume the web service to get the correct classes of the web service.
I've investigated a numerous of ways to do this. For example I've tried consuming them with a script and then just import the classes.
However, a colleague of my recommended that I would try using the Maven-plugin wsdl2code since we already use Maven-2 . Doing this works but creates a lot of junk files as I see it. I've added following into my pom.xml file:
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>ws.client.test</packageName>
<wsdlFile>http://localhost:8088/test?WSDL</wsdlFile>
<databindingName>xmlbeans</databindingName>
<outputDirectory>target/ws/test</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
This creates the files successfully, but as said, there's also a lot of junk files(
xmlsoap/schemas/soap/encoding/...) or at least a lot more files for no use (as I see it) than the other WSDLconsume I tried.
Questions
Is there a general guidelines how to
consume a web service? Since the WSDL
file is external it could also be
changing, and therefor I thought
it could be good having this done
automatically in Maven (though there
would be other side effects if the
WSDL suddenly changed...).If the wsdl2code is a good choice, should all the files always be created in the target-catalouge so
that they are being removed when executing mvn clean)?Is there any other tool that might fit better?
Update/Edit
By using for example JAX-WS wsimport I get the generated files that I desire.
However, by having these created in the /target-folder I want to reach them in the same project to actually call the web service. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有 java-1.6,您可以(应该)使用 jax-ws,使用板载 java 工具非常容易。有一个很好的 Maven 插件可以创建一个 Web 服务客户端,无需任何额外的依赖即可使用。看看 http://jax-ws-commons.java.net/ jaxws-maven-plugin/
请参阅http://blogs.oracle.com/enterprisetechtips/ Entry/using_jax_ws_with_maven 了解详细演练。
If you have java-1.6 you can (should) use jax-ws, its very easy with onboard java tools. There is a good maven plugin that will create a webservice client, that can be used without any additional dependencies. Have a look at http://jax-ws-commons.java.net/jaxws-maven-plugin/
See http://blogs.oracle.com/enterprisetechtips/entry/using_jax_ws_with_maven for a detailed walkthrough.
您可以尝试 CXF wsdl2java 插件。此外,最好将生成的源代码存储在单独的源文件夹中以避免混乱。所以最后的配置如下所示:
You can try CXF wsdl2java plugin. Also it's a good idea to store generated source in a separate source folder to avoid mess. So finally the configurations looks like this: