The WebService of Java EE

Source: Internet
Author: User

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

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.