First, create a new Web project,
1. Open the Axis2.war package, copy the Conf,lib,modules three folders to the Web-inf folder of the project, and create a new services folder under the Web-inf directory. Then create a new folder under the Services file (any name);
Then new Meta-inf folder, and finally add services.xml, interface information is written in this area.
Specific path: Web-inf/services/myservice/meta-inf/services.xml
2. Configure Web. Xml. Load Axis2 and Applicationcontext.xml.
<!-- Load Profiles --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> < param-value>classpath:/*.xml</param-value> </context-param> <!-- Load axis2 --> <servlet> <display-name>Apache-Axis Servlet</display-name> <servlet-name>axisServlet</servlet-name> < servlet-class>org.apache.axis2.transport.http.axisservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet > <servlet-mapping> < servlet-name>axisservlet</servlet-name> < Url-pattern>/services/*</url-pattern> </servlet-mapping>
3. Then create the package under SRC in the project and create a class under the package to provide the Web service interface.
Package Com.axis.service;public class Testaxis {public string test (String str) {return ' test ' + str; } public string Printhello (string name) {return "Hello" + name; } public string Printworld (string name) {return ' world ' + name; }}
4. Configure the Services.xml file.
<?xml version= "1.0" encoding= "UTF-8"? ><service name= "Axisservice" targetnamespace = "HTTP://E3.ORG/AXIS2NAMESPACE/SOAPWS" > <!-- Service Name Description --> <description>axis2 Interface Development Example </description> <!-- Namespaces can be freely defined --> <schema schemanamespace= "http://e3.org/axis2Namespace/ SOAPWS " /> <!-- type of direct write position --> <!-- <parameter name= "ServiceClass" >com.axis.service.TestAxis</parameter> --> <!-- Mode Two, point to the class location, through applicationcontext.xml configuration --> <parameter name= "Springbeanname" >CrjWs</parameter> <parameter Name= "Serviceobjectsupplier" > Org.apache.axis2.extensions.spring.receivers.SpringServletcontextobjectsupplier </parameter> <!-- Way One --> <operation name= "Test" > <messagereceiver class= "Org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> <operation name= "PrintHello" > <messagereceiver class= " Org.apache.axis2.rpc.receivers.RPCMessageReceiver " /> </operation> <operation name= "Printworld" > <messagereceiver class= "Org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> <!-- Way Two --> <!-- &Nbsp;<messagereceivers> <messagereceiver mep= " Http://www.w3.org/2004/08/wsdl/in-out " class= "Org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> <messagereceiver mep= "Http://www.w3.org/2004/08/wsdl/in-only" class= "Org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> </messageReceivers> --> <!-- Shielded interface --> <excludeOperations> <operation>printhello</operation> </ Excludeoperations></service>
5. configuration file Applicationcontext.xml.
<!--WebService Inlet bean--<bean id = "Crjws" class= "Com.axis.service.TestAxis"/>
6. Directory structure.
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650; src=/e/ U261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") No-repeat center;border:1px solid #ddd; "alt=" Spacer.gif "/>650" this.width=650; "src=" http://s3.51cto.com/wyfs02/ M01/82/0e/wkiom1djt4cch5n_aaa4awuyw00628.png-wh_500x0-wm_3-wmp_4-s_3686392662.png "title=" Clipboard.png "alt=" Wkiom1djt4cch5n_aaa4awuyw00628.png-wh_50 "/>
7. Run the project and use the browser to access the address
HTTP://LOCALHOST:8080/WEBSERVICETEST/SERVICES/AXISSERVICE?WSDL,
If there is any exception information, then return to see if the jar is missing or other configuration reasons, I will look at the beginning to see if there is no configuration.
If successful, a copy of the WSDL page is displayed on the page.
Second, the following are some of the small problems I encountered.
1, reported the service_object_supplier parameter is not specified.
Check out the discovery that there is no write listener. Add in the Web. xml file
<listener> <listener-class> Org.springframework.web.context.ContextLoaderListener </listener-class ></listener>
If you use Springbeanname, you need to load serviceobjectsupplier.
<parameter name= "Springbeanname" >CrjWs</parameter> <parameter name= "Serviceobjectsupplier" > Org . Apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier </parameter>
Third, the client calls.
Package com.test;import javax.xml.namespace.qname;import org.apache.axis.client.call;import org.apache.axis.client.Service;public class webTest { public Static void main (String[] args) { string _newendPoint = "http:/ /LOCALHOST:8080/WEBSERVICETEST/SERVICES/AXISSERVICE?WSDL "; string _newnamespace = "HTTP://E3.ORG/AXIS2NAMESPACE/SOAPWS"; try { Service Service = new service (); call call =&nBSP; (call) service.createcall (); Call.settargetendpointaddress (New java.net.url (_newendpoint)); call.setoperationname (New qname (_newnamespace, "test")); String s = (String) Call.invoke (new object[] {"test123"}); system.out.println (s); // call.setoperationname (New qname (_newnamespace, "Printhello")); // s = (String) call.invoke (new object[] { "printHello456"}); // System.out.println (s); &nbsP; call.setoperationname (New QName (_newNameSpace, "Printworld")); s = ( String) call.invoke (new object[] { "printWorld789" &NBSP;}); system.out.println (s); } catch (Exception ex) { ex.printstacktrace (); } }}
This article is from the "sea-wide _ Starry Sky" blog, please be sure to keep this source http://7852586.blog.51cto.com/7842586/1784076
AXIS2 Implementing Web Service Interface Development + client invocation