The difference between this example and the reference article is:
1) deploy.wsdd is defined in more detail (the interface is defined for the server side: ICalculate):
Copy the code code as follows:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="Calculate" provider="java:RPC" style="rpc" use="literal">
<parameter name="wsdlTargetNamespace" value="http://web.webservice.CalculateService.org" />
<parameter name="wsdlServiceElement" value="Calculate" />
<parameter name="wsdlServicePort" value="CalculateService" />
<parameter name="wsdlPortType" value="ICalculate" />
<parameter name="className" value="org.calculateservice.service.CalculateImp" />
<parameter name="typeMappingVersion" value="1.2" />
<parameter name="allowedMethods" value="add sub" />
<parameter name="scope" value="Request" />
<operation name="add" qname="operNS:add"
xmlns:operNS="http://web.webservice.CalculateService.org"
returnQName="addReturn" returnType="rtns:int" xmlns:rtns="http://www.w3.org/2001/XMLSchema"
soapAction="">
<parameter qname="x" type="tns:int"
xmlns:tns="http://www.w3.org/2001/XMLSchema" />
<parameter qname="y" type="tns:int"
xmlns:tns="http://www.w3.org/2001/XMLSchema" />
</operation>
<operation name="sub" qname="operNS:sub"
xmlns:operNS="http://web.webservice.CalculateService.org"
returnQName="subReturn" returnType="rtns:int" xmlns:rtns="http://www.w3.org/2001/XMLSchema"
soapAction="">
<parameter qname="x" type="tns:int"
xmlns:tns="http://www.w3.org/2001/XMLSchema" />
<parameter qname="y" type="tns:int"
xmlns:tns="http://www.w3.org/2001/XMLSchema" />
</operation>
</service>
</deployment>
2) Customized AxisServlet: org.calculateservice.core.AxisServlet (compatible with .NET and removing the SOAPACTION check);
The detailed code is not posted here. If you are interested, you can download the complete sample code by yourself;
3) The calling method is to use a local class to call (there seem to be three ways to call WS in Java. Personally, I feel that using a local proxy class to call is the most reasonable and readable):
Copy the code code as follows:
public static void main(String[] args) throws ServiceException, RemoteException {
Calculate calculate = new CalculateLocator();
int result = calculate.getCalculateService().add(1, 2);
System.out.println("[%1 + 2 = " + result + "%]");
}
Main steps to publish/call WS: 1) Copy the axis directory in the webapp in the axis1.4 installation package in the downloaded resource to the webapp directory in tomcat;
2) Write WS server implementation code;
3) Write the deploy.wsdd deployment file in the WEB-INF directory;
4) Write: generate-server-config.bat script, then generate: server-config.wsdd, and then publish webservice;
5) Write: wsdl2java.bat script to generate local calling client code;
6) Write test code to call WS;
Code structure diagram:
client: Use WSDL2Java to generate local client code based on wsdl;
core: Custom AxisServlet, compatible with .NET and removes the SOAPACTION check;
service: WS server implementation code (a simple addition and subtraction calculation is used as an example here);
test: Call the server based on the generated client class (the server address of the generated code is localhost. If you need to change this address to configuration, just modify the assignment of the variable CalculateService_address in the CalculateLocator class);
Click to download the complete example
The resource contains sample complete code and axis1.4 installation files