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.
Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.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

  • Pingback: alkaline water brands()

  • Pingback: water ionizer loan()

  • Pingback: pay per day loan plans()

  • Pingback: alkaline water()

  • Pingback: water ionizers()

  • Pingback: mp4 mobile porn()

  • Pingback: stop parking()

  • Pingback: laan penge nu og her 18 aar()

  • Pingback: car parking()

  • Pingback: check out DIRECTV channels()

  • Pingback: DirectTV()

  • Pingback: Business DIRECTV()

  • Pingback: uk online casinos()

  • Pingback: spider vpn()

  • Pingback: kangen water machine()

  • Pingback: kangen()

  • Pingback: Blue Coaster33()

  • 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

  • http://yogendra.me 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

    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 to use wsimport (or any other tool) to generate classes with annotations (this is my main concern) becouse wsdl2java generates a lot of code old-style?

    Regards,

    • Shyam

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

      • 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)

  • http://www.slideshare.net/jeangraves837/fhea-coupons-huge-savings 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.

  • http://[email protected] 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

      hi , how do u use wsimport with -xauthfile
      tnx

  • Calvin

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

  • Calvin

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

  • 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

    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

      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

    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

      use -p option
      -p com.org.proj

  • Javabuddy

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

  • Pingback: JAX-WS Tutorial()