Web Service Learning-CXF Development Web Service Instance demo (i)

Source: Internet
Author: User
Tags wsdl


What is a Web Service?

Web Service not a framework, not even a technology. But a cross-platform, cross-language specification

what the Web Service solves:

To solve different platforms, how to invoke the problem between apps written by different languages. For example, there is a C Language program that wants to call A method written in the Java language.

Centralized Solution: 1 , the remote call 2 , cross-platform invoke 3 , cross-language calls

Practical application:

1 , the integration of the new and old systems of the same company. Java applications on Linux to invoke the C Application of the Windows platform

2 , the business integration of different companies. Business integration leads to the integration of different companies, different systems may have different platforms, different language issues

3 , content aggregation. An application, such as the need to provide, weather forecasts, stock quotes, gold quotes and so on.

The relationship between cxf and web Service

CXF is Apache's Open source framework, composed of two classic frameworks, celtix+ Xfire, which is a very popular Web service framework.

CXF Way to implement Web Service service demo

1, configuring environment variables


Add E:\apache-cxf-2.6.2\lib to Classpath

New cxf_homee:\apache-cxf-2.6.2

Add%cxf_home%\bin in Path




2, using CXF to develop Web Service Development Server-side

The directory structure of the entire project (normal Java project):




Interface:

Package Com.tgb.service;import javax.jws.WebService; @WebServicepublic interface Helloworld{public String Sayhi ( String name);}

Implementation class:

Package Com.tgb.service.impl;import Java.util.date;import Javax.jws.webservice;import com.tgb.service.HelloWorld;@ WebService (endpointinterface= "Com.tgb.service.HelloWorld", Servicename= "Helloworldimpl") public class Helloworldimpl implements Helloworld{public string Sayhi (string name) {return name+ "Hello!" Now the time is: "+new date ();}}


To test the client:

Package Com.tgb.client;import Javax.xml.ws.endpoint;import Com.tgb.service.helloworld;import Com.tgb.service.impl.helloworldimpl;public class Servermain {public static void main (string[] args) {HelloWorld hw=new Helloworldimpl ();//Call Endpoint's Publish method to publish the Web Serviceendpoint.publish ("Http://192.168.24.215/hjy", HW); SYSTEM.OUT.PRINTLN ("Web service exposed successfully");}}

Start the program:




View WSDL




3, Develop WebService client using CXF

Execute the following command (locate WebService execution of the client's workspace)





Refresh the client project to see the following generated code:




Write the client calling code:


Package Hjy;import Com.tgb.service.helloworld;import Com.tgb.service.impl.helloworldimpl;public class ClientMain { public static void Main (string[] args) {Helloworldimpl factory=new helloworldimpl ();//The only remote Web that is returned here Service agent HelloWorld Hw=factory.gethelloworldimplport (); System.out.println (Hw.sayhi ("Hejingyuan"));}}

Execution Result:

Hejingyuan Hello! Current time: Tuejul 14:09:07 CST 2015

Summary:

Use CXF Development Web There are several steps to service:

1 , server-side

( 1 ) Develop a web Service business interface. The interface is to be decorated with @webservice

( 2 ) Develop a web service Business implementation class. The implementation class also needs to be decorated with @webservice

( 3 ) Publish the Web Service

2 , the client

( 1 ) Call CXF provided by WSDL 2java tools, according to WSDL the document generates the corresponding Java code.

wsdl- Web Service Definition Language

any language implements the Web Service, both need to be provided, and expose the WSDL document

( 2 ) to find WSDL 2java in the generated class, one inherits the Service the class

Instances of this class can be used as a factory

( 3 ) Call Service instance of the subclass . Get Xxxport method to return to the remote Web agent for service



SOURCE download



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Web Service Learning-CXF Development Web Service Instance demo (i)

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.