简体   繁体   English

给定WSDL文件,创建一个简单的Java客户端

[英]Given a WSDL file, create a simple Java client

Can anyone please provide me with a sample code for this? 任何人都可以为我提供一个示例代码吗? I have a wsdl file, and I want to create a client that will call a service from that wsdl file 我有一个wsdl文件,我想创建一个从该wsdl文件调用服务的客户端
A working code with some explanation will be really helpful. 带有一些解释的工作代码将非常有用。

I'm using JDK 1.4. 我正在使用JDK 1.4。

The main options are to use: 主要选项是使用:

  1. JAX-WS, using the wsimport tool . JAX-WS,使用wsimport工具
  2. Apache AXIS2, using wsdl2java . Apache AXIS2,使用wsdl2java

Both links provide code examples. 两个链接都提供代码示例。 Some searching on the web will get you even farther. 一些在网上搜索会让你更进一步。 There are also options for creating dynamic SOAP clients but the generated ones are easiest. 还有创建动态SOAP客户端的选项,但生成的客户端最简单。

You can do it from command line using wsimport provided by JAX-WS 您可以使用JAX-WS提供的wsimport从命令行执行此操作

wsimport -keep -s (output folder) urlToWsdl wsimport -keep -s(输出文件夹)urlToWsdl

> ex : wsimport -keep -s {homeDirectory}/OutputFolder https://www.example.com

PS: while using non-standard SOAP 1.2 binding. PS:同时使用非标准的SOAP 1.2绑定。 You must specify the "-extension" option to use this binding. 您必须指定“-extension”选项才能使用此绑定。

for further reading visit this 进一步阅读访问

One of the many possible tools is WSDL2Java . WSDL2Java是众多可能的工具之一。 In a shell: 在一个shell中:

$ java org.apache.axis.wsdl.WSDL2Java foo.wsdl

NetBeans可以为您生成大量代码:文件 - >新文件... - > Web服务 - > Web服务客户端

Eclipse is having the option to generate java client. Eclipse可以选择生成java客户端。
Just Right click on the WSDL file 只需右键单击WSDL文件即可
Generate Web Service Client 生成Web服务客户端
Thatz all. 那就是全部。 You get the client to invoke the SOAP Service 您可以让客户端调用SOAP服务

I've seen Apache Axis do this automatically. 我见过Apache Axis会自动执行此操作。 You may want to try that to get to know a little about it. 你可能想尝试一下来了解它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM