Detailed explanation of using Axis to publish/call Webservice in JAVA

Source: Internet
Author: User

The difference between this example and the reference document is as follows:

1) deploy. wsdd ):

Copy codeThe Code is 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) custom AxisServlet: org. calculateservice. core. AxisServlet (compatible with. NET and removed the SOAPACTION test );

The detailed code is not pasted here. You are interested in downloading the complete sample code;

3) The call method is local class call (java WS call seems to have three methods, and I personally feel that local proxy class calls are the most reasonable and readable ):

Copy codeThe Code is 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 + "%]");
}

Steps for publishing/calling WS:

1) copy the axis directory of the webapp in the axis1.4 installation package from the downloaded resource to the webapp directory in tomcat;

2) write the WS server implementation code;

3) Write deploy. wsdd deployment file in the WEB-INF directory;

4) Write: generate-server-config.bat script, and then generate: server-config.wsdd, and then publish webservice;

5) write the wsdl2java. bat script to generate the local client code;

6) Compile the test code to call WS;

Code structure:

Client:Use WSDL2Java to generate local client code based on wsdl;

Core:The custom AxisServlet is compatible with. NET and removes the SOAPACTION test;

Service:WS server implementation code (Here we use a simple addition and subtraction calculation as an instance );

Test: call server according to the generated client class (the generated code server address is localhost. If you need to change this address to configuration, modify the value of the variable CalculateService_address in the CalculateLocator class );

Click to download the complete example

The resource contains the complete sample code and the axis1.4 Installation File.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.