Original works, permission to reprint, please be sure to use hyperlinks in the form of the original source of the article, the author information and my statement. Otherwise, the legal liability will be investigated. Eternal の_☆ Address: http://blog.csdn.net/chenghui0317/article/details/9318317
I. INTRODUCTION of AXIS
Web Service is now the most suitable technology for implementing SOA, and axis is a technical framework (architecture) for implementing Web service.
Ii. conditions of readiness for axis
Required JAR Packages:
Axis.jar
Jaxrpc.jar
Saaj.jar
Wsdl4j-1.5.1.jar
Commons-discovery-0.2.jar
Xbean.jar
: http://download.csdn.net/detail/ch656409110/5747129
Third, create WebService server 1, first put the jar package into the Lib directory 2, configure the Axis listener and the core servlet in Web. xml
1 <!--Axis Configuration - 2 <Listener> 3 <Listener-class>Org.apache.axis.transport.http.AxisHTTPSessionListener</Listener-class> 4 </Listener> 5 <servlet> 6 <Display-name>Apache-axis Servlet</Display-name> 7 <Servlet-name>Axisservlet</Servlet-name> 8 <Servlet-class>Org.apache.axis.transport.http.AxisServlet</Servlet-class> 9 </servlet> Ten <servlet> One <Display-name>Axis Admin Servlet</Display-name> A <Servlet-name>Adminservlet</Servlet-name> - <Servlet-class>Org.apache.axis.transport.http.AdminServlet</Servlet-class> - <Load-on-startup>100</Load-on-startup> the </servlet> - <servlet-mapping> - <Servlet-name>Axisservlet</Servlet-name> - <Url-pattern>/servlet/axisservlet</Url-pattern> + </servlet-mapping> - <servlet-mapping> + <Servlet-name>Axisservlet</Servlet-name> A <Url-pattern>/services/*</Url-pattern> at </servlet-mapping> - - -}
View Code
3, create an XML, named Server-config.wsdd in the Web-inf root directory
1 <?XML version= "0" encoding= "UTF-8"?> 2 3 <Deploymentxmlns= "http://xml.apache.org/axis/wsdd/"Xmlns:java= "Http://xml.apache.org/axis/wsdd/providers/java"> 4 <Handlername= "Urlmapper"type= "Java:org.apache.axis.handlers.http.URLMapper"/> 5 6 <Servicename= "Housewebservice"provider= "Java:rpc"> 7 <parametername= "Allowedmethods"value="*"/> 8 <parametername= "ClassName"value= "Com.strutswebservice.server.HouseWebServiceImpl"/> 9 </Service> Ten One <Transportname= "http"> A <Requestflow> - <Handlertype= "Urlmapper"/> - </Requestflow> the </Transport> - </Deployment>
View Code
4, according to the configuration and then create the WebService service end of the implementation class
1. Define Interface Housewebservice.java
public string Gethouselist (string xmlstr);
2. Implement the interface Housewebserviceimpl.java
You can simply return some strings.
5, save, release the project, start Tomcat
In the Address bar, enter: http://localhost:8080/house/services/houseWebService?wsdl to see the details of the published service side.
As follows:
This means that the WebService server that was released by Axis is successful.
6. Call the service-side webservice through the client
/** * Call WebService Intersection * @param endpoint Address * @param method of MethodName call * @param xmlstr passed XML string parameter * @return */Public String Invoke (string endpoint,string methodname,string xmlstr) {Service service = n EW Service (); Call call = NULL; try {call = (call) Service.createcall (); } catch (Serviceexception e) {e.printstacktrace (); } QName qn = new QName (methodName); Call.setoperationname (QN); Call.settargetendpointaddress (endpoint); Call.setusesoapaction (TRUE); String result = ""; try {//Pass parameter to method, and call method result = (String) call.invoke (new object[] {xmlstr}); } catch (RemoteException e) {e.printstacktrace (); } System.out.println ("result is" + result); return result; } public listIn this case, the XML specification passed by the server itself, and then to parse, get parameters, perform the corresponding operation, return the desired results to the calling client.
It is convenient to use the service side of axis to invoke axis, but the service side of calling CXF is prone to error.
For example: If you do not specify a namespace at the time of the call, you cannot.
The parameters that are sent by the client are not received when the calling parameter is not specified and the result type is returned. can see: http://blog.csdn.net/ch656409110/article/details/9310789
Axis creates WebService client and server