1.WebService
A. Definition: WebService is a remote call technology across programming languages and cross-operating system platforms
B. Three major technologies: XML+XSD,SOAP,WSDL
C.SOAP Protocol = HTTP protocol + XML data format
D.WSDL: XML-based description language (equivalent to dictionaries, menus)
2. Service side:
A. Configuring in XML
<Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <!--Configuring the core servlet of the CXF framework - <servlet> <Servlet-name>Cxfservlet</Servlet-name> <Servlet-class>Org.apache.cxf.transport.servlet.CXFServlet</Servlet-class> <Load-on-startup>2</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Cxfservlet</Servlet-name> <Url-pattern>/server/*</Url-pattern> </servlet-mapping>
B. Building Spring-webservice.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:jaxws= "Http://cxf.apache.org/jaxws"xsi:schemalocation= "Http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/ Beans Http://www.springframework.org/schema/beans/spring-beans.xsd "Default-lazy-init= "true"> <BeanID= "Webserviceserver"class= "Com.wode.server.impl.MyWebServiceImpl" /> <Jaxws:endpointID= "MyService"implementor= "#webserviceServer"Address= "/helloservice"> </Jaxws:endpoint> </Beans>
C. Building interfaces
@WebService Public Interface MyWebService { int int int b); int int int b); }
D. Building implementation Class
@WebService (endpointinterface = "Com.wode.server.MyWebService") Public classMywebserviceimplImplementsMyWebService {@Override Public intAddintAintb) {//TODO auto-generated Method StubSystem.out.println (A +b); returnA +b; } @Override Public intMinus (intAintb) {//TODO auto-generated Method StubSystem.out.println (A-b); returnA-b; }}
E. Testing (need to run Tomcat server Tomcat:run first)
New Jaxwsproxyfactorybean (); Factorybean.setserviceclass (MyWebService. class ); Factorybean.setaddress ("Http://127.0.0.1:8080/myService/server/HelloService"); MyWebService Service=(MyWebService) factorybean.create (); System.out.println (Service.add (1, 3));
F. Access http://127.0.0.1:8080/myService/server/HelloService?wsdl confirm that it is normal
G. Download apache-cxf-3.1.11 and configure environment variables
H. In console input
Wsdl2java-encoding Utf-8-D E:\EclipseWorkspace\myService http://127.0.0.1:8080/myService/server/HelloService?wsdl
I. Copy the project under the COM folder into the client project
3. Client
A. Use
Mywebserviceimplservice service=New mywebserviceimplservice (); MyWebService MyWebService=service.getmywebserviceimplport (); System.out.println (Mywebservice.add (Ten) + "client");
The WebService of Java EE