Problem:
This is one of the Common Exceptions which we come across daily in our lives. When i was trying to run wscompile command to generate java client classes from a WSDL file.
Exception i encountered was:
"invalid element "{http://schemas.xmlsoap.org/wsdl/}definitions" in configuration file (line 2)"
Solution:
The real culprit for this exception was config.xml file. I just copy pasted the complete WSDL file into the config.xml file instead of just refering WSDL file.
For example:
Syntax for Config.xml file:
*******************************************************************************************************************************************************************
The wscompile command reads the config.xml file, which has the information about web service. This is how config.xml file looks:
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<service> or <wsdl> or <modelfile>
</configuration>
The <configuration> element may contain exactly one <service>, <wsdl>, or <modelfile> element.
The <service> Element
If you specify this element, wscompile reads the service endpoint interface that describes the service and generates a WSDL file. In the <interface> subelement, the name attribute specifies the service endpoint interface, and the servantName attribute specifies the class that implements the interface. For example:
<service name="CollectionIF_Service"
targetNamespace="http://echoservice.org/wsdl"
typeNamespace="http://echoservice.org/types"
packageName="stub_tie_generator_test">
<interface name="stub_tie_generator_test.CollectionIF"
servantName="stub_tie_generator_test.CollectionImpl"/>
</service>
The <wsdl> Element
If you specify this element, wscompile reads the service's WSDL file and generates the service endpoint interface. The location attribute specifies the URL of the WSDL file, and the packageName attribute specifies the package of the classes generated by wscompile. For example:
<wsdl
location="http://tempuri.org/sample.wsdl"
packageName="org.tempuri.sample" />
The <modelfile> Element
This element is for advanced users.
If config.xml contains a <service> or <wsdl> element, wscompile generates a model file that contains the internal data structures that describe the service. If you've already generated a model file in this manner, then you can reuse it the next time you run wscompile. For example:
<modelfile location="mymodel.xml.gz"/>
*******************************************************************************************************************************************************************
Command:
java com.sun.xml.rpc.tools.wscompile.Main -gen:client -d <<Give the destination folder>> <<config.xml>> C:\Rahamat\Axis\wscompile\config.xml
Similar Exceptions:
- Exception Occured invalid element "{http://schemas.xmlsoap.org/wsdl/}definitions" in configuration file (line 2)