JAX-WS : wsimport tool example

The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files (JAX-WS portable artifacts) for web service client to access the published web services. This wsimport tool is available in the $JDK/bin folder.

Use Case

An common use case of this wsimport tool.

1. Server – Published web service – WSDL file.

The CompA has published a web service along with a WSDL file at URL : http://compA.com/ws/server?wsdl

2. Client – Access the published service.

For CompB, to develop a web service client to access the CompA published web service, they can use wsimport tool to parse CompA’s WSDL file and generate files (JAX-WS portable artifacts) to access CompA’s published service.

Command : wsimport command to parse CompA WSDL file


C:\>wsimport -keep -verbose http://compA.com/ws/server?wsdl
parsing WSDL...

generating code...
com\mkyong\ws\ServerInfo.java
com\mkyong\ws\ServerInfoImplService.java
Note
For complete example, please visit this JAX-WS hello world example article, refer to the section “2. Java Web Service Client via wsimport tool“.

For other use cases or usages, please visit reference links below.

References

  1. Metro : wsimport tool
  2. IBM – wsimport command for JAX-WS applications.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Calvin
Guest
Calvin

How can we convert wsdl to JAR file using wsimport.exe? Thanks.

abel
Guest
abel

Hi. wsimport is only for the side client?

Jon Inazio
Guest
Jon Inazio

How to generate client stubs from more than one WSDL that have some objects in common? I’m trying to overcome this problem, as ObjectFactory gets overwritten. Thanks !!

ravitej reddy
Guest
ravitej reddy

HI i have genrated the client but i am unable to generate its helper classes like helper.class ser.class and desrv.class files … Can you please help on this

zen
Guest
zen

Can you tell me where I might have gone wrong or a way to debug this.

C:newfolder2>wsimport -keep C:UserssjangoanDesktopoppwsdl.xml

parsing WSDL…

[ERROR] found unexpected non-whitespace text: “áááá”

Failed to parse the WSDL.

hadi
Guest
hadi

how to generate server stubs from wsdl?

Meg07
Guest
Meg07

How can we access a wsdl of a soap project whose war is deployed on the same server, by a Rest based project using spring maven.

Basically , I have to access an API that is exposed via wsdl and I have to access this API, the response than needs to be returned as json from a rest POST method. It will be like a REST post method, accepting the inputs and invoking this API (from wsdl) and manipulating the response as JSON,

Thanks in advance,

Govindh G
Guest
Govindh G

Hi,

i have followed your steps C:>wsimport -keep -verbose http://compA.com/ws/server?wsdl and i got java files.

But when i call webservice method it throws below exception

javax.xml.ws.soap.SOAPFaultException: Missing required SOAP header.

at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)

at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:119)

at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)

at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)

at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy36.queryCSV(Unknown Source)

at fromcmdrightnow.Class1.getContactSample(Class1.java:90)

at fromcmdrightnow.Class1.main(Class1.java:31)

How to add soap header without using axis2 jar.

Note : I have to call soapheader method but i dont want use axis2 jar. is there any possible?

Thanks Govindh

Praveen
Guest
Praveen

Im learning jax ws

im working with jdk 1.5 .6 22update

wsimport command is not working while creating jax-b binding classes in provider side

KVR
Guest
KVR

Hi,

I am facing below error while parsing WSDL file in to java classes. Could you please help me to resove this issue.
[ERROR] Failed to read the WSDL document: http://www.xignite.com/xcurrencies.asm
x?WSDL, because 1) could not find the document; /2) the document could not be re
ad; 3) the root element of the document is not .
unknown location.

Thanks,
KVR

Yogendra Rampuria
Guest
Yogendra Rampuria

Try http://www.xignite.com/xcurrencies.asmx?wsdl. i think you are missing an ‘x’ at the end. And also, this looks like a paid service, so you have to ensure that your account is configured properly

Yogi
Guest
Yogi

I arrived on this post looking for a way to use proxy for internal (intranet) URLs and skip proxy for external URLs (w3c.com) using the wsimport.exe (part of JDK 1.6, 1.7,etc). I see that it does not have the facility to put nonProxyHosts, so I went ahead and used Java class invocations.

Something like this
java -Dhttp.proxyHost=proxyServer -Dhttp.proxyPort=9000 -Dhttp.nonProxyHosts=”localhost|other-maching-on-lan|*.intranet-domain” -classpath %JAVA_HOST%\lib\tools.jar com.sun.tools.internal.ws.WsImport -p com.ws.client.pkg http://my-internal-domain/endpoint?wsdl

vexed man
Guest
vexed man
Hello I want to generate classes from wsdl file provided to me. I tried to use 1. wsimport: (output) Schema descriptor {http://somename}SomeFile in message part “parameters” is not defined and could not be bound to Java. Perhaps the schema descriptor {http://somename}SomeFile is not defined in the schema imported/included in the WSDL. You can either add such imports/includes or run wsimport and provide the schema location using -b switch. line 17 of file:/C:/SomeFile.wsdl 2. xjc (output) parsing a schema… compiling schema… 3 only axis2 wsdls2java generated me classes . My questions are, what could be the problem and what to do… Read more »
Shyam
Guest
Shyam

using JAXB or use ANT task to create the the client components . so that you can bind your classes with annotation .

vexed man
Guest
vexed man

If I understand correctly Your solution, I am not able to do this. All I have is .wsdl and schemas and i will not get another ones (I’m not owner of service and owner won’t privide me another one generated with JAXB)

rebecca
Guest
rebecca

Greetings I am so thrilled I found your blog,
I really found you by mistake, while I was searching on Askjeeve for something
else, Regardless I am here now and would just like to say many
thanks for a incredible post and a all round interesting blog (I also love the
theme/design), I don_t have time to go through it all at the
moment but I have saved it and also included your RSS feeds, so when I have time
I will be back to read a lot more, Please do keep up the superb b.

Jeff
Guest
Jeff

I have a windows-based service I need to generate a client, but it requires authentication. I’ve gotten a successful call with my personal username/password using the -XauthFile option, but our “service” account password has special characters and I don’t know how to encode it. I tried encoding the full URL but get an error parsing it. Do you have an example of how to encode the username/password of a URL in an authFile that will work with wsimport? I’ve been unsuccessful so far finding a working example.

hanane
Guest
hanane

hi , how do u use wsimport with -xauthfile
tnx

Calvin
Guest
Calvin

How do we create convert the wsdl into a JAR file using wsimport?

Shyam
Guest
Shyam
Nik
Guest
Nik

how to generate equals() and hashcode() methods for the Type class using wsimport ?

I need to put Type object in ehcache. so need to implement equals() and hashcode() in Type object

CypraxPuch
Guest
CypraxPuch

How can i handle a java.util.HashMap in my web service as parameter.

I have my WS with a HashMap, but the props is always empty when i do the request from my client.

Example:

@WebService
public class MyServiceImpl implements MyService {

   @Override
   @WebMethod
   String searchProps(@WebParam(name="props") HashMap<String, String> props){

     if( props!=null && !props.isEmpty()){
        System.out.println("do something");
     }else{
        System.out.println("always is empty");
     }

   }
}
CypraxPuch
Guest
CypraxPuch

well, the solution was to make a wrapper for my java HashMap, and use it as my parameter.

public class MapWrapper {
	public HashMap<String, String> properties;
}

String searchProps(@WebParam(name="props") MapWrapper props){...}

thank you, any way!!!

Azhar
Guest
Azhar

Thank you very much,I have a doubt
if wsdl file is available with us,
What is the option to generate the proxy with custom package structure

I have MyWsdl.wsdl , I want to generate the proxy , the generated classess into some package say com.myex.client.bidigs , could you please help me on this

Ex:-
wsimport -s src -d bin MyWsdl.wsdl
above command has generated the java files in src and class files in bin with some package structure I wanted to give my own , please suggest me how can i give.

Surendra
Guest
Surendra

use -p option
-p com.org.proj

Javabuddy
Guest
Javabuddy

Thanks a ton. I was struggling to find correct command for wsimport. Now m able to generate my wsdl docs.

trackback
JAX-WS Tutorial

[…] “TCP/IP Monitor” in Eclipse IDE, and also intercept the SOAP messages generated by web service.JAX-WS : wsimport tool example The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and […]

Marlan
Guest
Marlan

I have imported java files using wsiport
wsimport -keep -verbose https://egpb-test.fin.ap1.oraclecloud.com/finArTrxnsInvoices/InvoiceService?WSDL

When I consume the SOAP request it generated this error

Exception in thread “main” com.sun.xml.ws.spi.db.DatabindingException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 83 counts of IllegalAnnotationExceptions
Two classes have the same XML type name “{http://xmlns.oracle.com/apps/financials/receivables/transactions/invoices/invoiceService/}JExRUAdditionalInfo”. Use @XmlType.name and @XmlType.namespace to assign different names to them.

wsdl url ;
https://egpb-test.fin.ap1.oraclecloud.com:443/finArTrxnsInvoices/InvoiceService?WSDL

What could be the issue and how to solve this?