Generating WSDL
To generate WSDL from an existing class, you can use the command line executable binaries provided by the Axis2 distribution, such as "wsdl2java." Axis2 documentation provides detailed instructions for using a binary both as a standalone binary and as an ANT task. The project also provides plug-ins for
Eclipse,
IntelliJ IDEA, and
Maven 2.
This article uses the Eclipse plug-in. Although, less powerful than the command line binaries, this plug-in makes the process of creating web services very efficient. It provides support for both WSDL-to-Java and Java-to-WSDL generations.
It's a good practice to place the web service-related code that is generated, including WSDL, in a separate project for better flexibility and clarity. Hence, before you generate your components, you need to create an empty Java project in the IDE with clear source and binary trees. Call this project AccountWS.
You can now use the Eclipse plug-in and generate WSDL from Java classes by referencing the AccountManagerImpl class. To ensure appropriate variable naming, make sure that the implementation classnot the interfaceis referenced. See the following screenshots for the details.
 Screenshot 1
|
|
 Screenshot 2
|
 Screenshot 3
|
|
 Screenshot 4
|
 Screenshot 5
|
A file named "services.wsdl" should be created under the new empty project AccountWS now. The WSDL now defines the two services with their input/output values, as follows:
<xs:element name="getAccount">
<xs:complexType>
<xs:sequence>
<xs:element name="accountId" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getAccountResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" nillable="true" type="ns0:Account" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="setStatus">
<xs:complexType>
<xs:sequence>
<xs:element name="accountId" nillable="true" type="xs:string" />
<xs:element name="status" nillable="true" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:element>
After the WSDL is generated, you need to manually edit the <soap:address> parameter, changing it to the right URL and port of the service. The plug-in generates a default value.