Create a java project using the created WSDL mentioned post Create a WSDL for a WebService

Initially the project structure will be like mentioned below.

1_pub_projectstructure

Generate the server code using Axis2CodeGen pluggin :

Select File > Select New > Click Other…

Select Axis2 Code Generator under the Axis2 Wizrds and Click Next

Select Generate the Java Source code from the WSDL file option and Click Next

Provide the WSDL file location eg : /rezsystem/workspace/MathService/src/gradethree/wsdl/GradeThreeMath.wsdl Use Browse button if you need.

Select
CodeGen Option : custom
Generate Service Side Code
Generate a default services.xml
Generate interface for Skeleton

Provide an Output Path (eg : /home/namal/Desktop/WORKS/WS/Math/Grade3). Use Browse button if needed.

Click Finish.

Take generated files to the project

This will generate the files mentioned in the LHS of the below image. Put those files in to the project as mentioned in the RHS.
Here, I have added resources and the server code to a seperate package (gradethree) since I have an intension to add another WebService within this same Project. You need to modify the package declarations in the Server Code and the services.xml

2_pub_folder_structure

Implement the logics in the GradeThreeMathSkeleton class.

eg : for Addition Operation


public gradethree.org.tempuri.AdditionResponse Addition(gradethree.org.tempuri.AdditionRequest additionRequest0){

AdditionResponse additionResponse = new AdditionResponse();

int operand1 = additionRequest0.getOperand1();
int operand2 = additionRequest0.getOperand2();

additionResponse.setResult(operand1+operand2);
additionResponse.setRemarks("This is enough for Grade Three Addition!");

return additionResponse;

}

Packaging : Generate the aar and jar files using the build.xml

Ant task :

<echo>Building GradeThreeMath AAR</echo>
<delete dir="${classes}/META-INF" />
<copy toDir="${classes}/META-INF" failonerror="false">
<fileset dir="${resources}/gradethree">
<include name="*.xml" />
<include name="*.wsdl" />
<include name="*.xsd" />
</fileset>
</copy>

<jar destfile="${lib}/GradeThreeMath.aar">
<fileset dir="${classes}">
<include name="META-INF/**" />
</fileset>
</jar>

<jar destfile="${lib}/GradeThreeMath.jar">
<fileset dir="${classes}">
<include name="gradethree/**" />
</fileset>
</jar>

So, this will return the GradeThreeMath.jar and GradeThreeMath.aar as follows.

3_pub-packaging

 

Deploy :

You can deploy them as mentioned below
4_pub-dployment

Start the server.

WSDL : http://localhost:8081/axis2/services/GradeThreeMath?wsdl

You can test the service using the SOAP UI with above WSDL as below

5_pub_soapui

You can add another service also within the same project, build/package with another ant task and deploy as mentioned in the below project.

6_pbl

Project lin : https://github.com/namalfernandolk/MathService.git

Advertisements