Wednesday, December 19, 2012

JAVA wsimport

Using wsimport to create client port to access a web service


There are 2 simple ways: download the wsdl xml file, or connect directly to wsdl url.

Needless to say you should go with the easiest way for you, e.g., if the WSDL is behind SSL connection you will find 1st option easier otherwise you would need aditional configuration to connect to the URL.

Option 1: you have the WSDL XML file

 /bin/wsimport.exe c:\wsdl.xml -verbose -s generatedSrc -wsdllocation  wsdl.xml

  • c:\wsdl.xml the WSDL file you downloaded
  • is the path to your JDK_HOME, I used 1.6.0_33
  • -verbose is to turn on verbose mode, so you can see details if a step fails 
  • -s is the option to set the destiny of the generated code 
  • generatedSrc is the path where you want your generated code to be created 
  • As you downloaded the WSDL file, you MUST use "-wsdllocation" option. Because if you don't use, wsimport will not create the javax.xml.ws.Service implementation class. 
If you get below error:
 [WARNING] Ignoring SOAP port "CadConsultaCadastro2Soap12":   
 it uses non-standard SOAP 1.2 binding.  
 You must specify the "-extension" option to use this binding.  
  line 59 of file:/C:/wsdl/cadconsultacadastro2.asmx.xml  
 [WARNING] Service "CadConsultaCadastro2" does not contain any usable ports.   
 try running wsimport with -extension switch.  
  line 58 of file:/C:/wsdl/cadconsultacadastro2.asmx.xml  

You will have to ignore SOAP12 by using "-extension" option:
 /bin/wsimport.exe c:\wsdl.xml -verbose -extension 

If the WS you are trying to connect uses headers, you should use "-XadditionalHeaders" option.
 /bin/wsimport.exe c:\wsdl.xml -verbose -extension -XadditionalHeaders

Option 2: you DO NOT have the WSDL XML file

 /bin/wsimport.exe  -verbose

  •  is the actual Web Service's URL

No comments:

Post a Comment