WebService Publishing Services: AXIS2 and client calls

Source: Internet
Author: User
Tags wsdl

1.axis2: Download the AXIS2 package to the official website. After decompression: 1. Copy the jar package under the Lib file into the Project 2. Create services->meta-inf->services.xml under Web-inf and compress the services.list in the package, Version-1.7.4.aar Copy to the Services folder 3. Write the Services.xml file, configure the published interface, in the following format: <?xml version= "1.0" encoding= "UTF-8"?>< Service name= "Testservice" targetname= "Http://cn.itcast.test" > <parameter name= "ServiceClass" > Cn.itcast.test.test</parameter> <operation name= "Add" > <messagereceiver class= "Org.apache.axi S2.rpc.receivers.RPCMessageReceiver "/> </operation> <operation name=" AAA "> <messager Eceiver class= "Org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </operation> <!--<operation N Ame= "Saysorry" > <messagereceiver class= "org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </ operation> <operation name= "Getworld" > <messagereceiver class= "Org.apache.axis2.rpc.receivers.RP Cinonlymessagereceiver "/> &LT;/OPERATION&GT --></service>4. Replace the written services.xml file with the Services.xml file in Version-1.7.4.arr (you can change the Version-1.7.4.arr suffix to zip and open the Find Services.xml file and replace it) in the 5.web.xml file configuration Axis2 servlet Filter in the following format: <?xml version= "1.0" encoding= "iso-8859-1"? ><web-app xmlns= "Http://java.sun.com/xml /ns/javaee "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://java.sun.com/    Xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "version=" 2.5 "> <display-name>Apache-Axis2</display-name> <servlet> <display-name>apache-axis SERVLET&L T;/display-name> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.apache.axi S2.transport.http.axisservlet</servlet-class> <load-on-startup>1</load-on-startup> </servle t> <!--<servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pa Ttern>/servlet/AxisServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-nam e>axisservlet</servlet-name> <url-pattern>*.jws</url-pattern> </servlet-mapping>--&G    T <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*& Lt;/url-pattern> </servlet-mapping> <!--<servlet-mapping> <servlet-name>axisadminser        Vlet</servlet-name> <url-pattern>/axis2-admin/*</url-pattern> </servlet-mapping>    <mime-mapping> <extension>inc</extension> <mime-type>text/plain</mime-type> </mime-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> &lt ;welcome-file>index.html</welcome-file> <welcome-file>/axis2-web/index.jsp</welcome-file> & Lt;/welcome-file-list> <error-page> <error-code>404</error-code> &LT;LOCATION&GT;/AXIS2-WEB/ERROR/ERROR404.J sp</location> </error-page> <error-page> <error-code>500</error-code> &L t;location>/axis2-web/error/error500.jsp</location> </error-page></web-app> boot server, WSDL document for the provider: HTTP://LOCALHOST:8080/AXIS2SERVER/SERVICES/TESTSERVICE?WSDL, if you have access to a Web-page XML format document, the interface is published successfully. Client generated code and call: Go to official website to download Axis2-1.7.4-bin There is a bin file, the bin file has a variety of. bat suffix command file, create a new custom. bat file, generally named Generatecode.bat (Chinese: Generate code), The contents of the file are as follows: Wsdl2java-uri http://localhost:8080/axis2Server/services/testService?wsdl-p axis2.service.server-o E:\CN The above statement means: Axis2.service.server is the directory structure; E:\CN is generated in the CN folder of the E-drive. However, the above Wsdl2java command needs to configure environment variables to execute, the configuration environment variables are as follows: System variable name: Axis2_home value: E:\axis2-1.7.4-bin\axis2-1.7.4; axis2_ HOME configuration in Path:%axis2_home%\bin, so AXIS2 environment variables are configured, run custom generatecode.bat files to generate code. AXIS2 Client calling Code: Package Cn.itcast.client;import Java.rmi.remoteexception;import Axis2.service.serveR.testservicestub;  public class Client {public static void main (string[] args) throws Exception {System.out.println (new Client () AA ());   System.out.println (New Client (). BB ());  } public String AA () throws Exception {//stub class testservicestub testservicestub = new Testservicestub ();  Add method Name: As a class new come out testservicestub.add Add = new Testservicestub.add ();    Put the new method name class as a parameter in the method you want to call Testservicestub.add (add);//The code here can be omitted, because the following has ligatures Testservicestub.add (add). Get_return (); return Testservicestub.add (Add). Get_return ();  } public String BB () throws remoteexception{testservicestub testservicestub = new Testservicestub ();  TESTSERVICESTUB.AAA Aaa = new Testservicestub.aaa ();    Aaa.seta ("Hello Jay Chou"); Return Testservicestub.aaa (AAA). Get_return (); }}

WebService Publishing Services: AXIS2 and client calls

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.