Java programmers from stupid birds to cainiao (one hundred and nine) Step by Step learn WebService (3) develop the first xfire-based WebService

Source: Internet
Author: User


In daily development, common WebService engines include axis, axis2, xfire, and cxf (upgraded version of xfire ). Currently, only official updates of axis2 and cxf are available. Today, we will take an old engine as an example. Let's talk about the main usage and simple principles of WebService.


Xfire is a new generation of Java Web service engine. xfire makes it easy to publish Web Services in Java EE applications. Compared with other Web service engines, xfire is easy to configure and can be easily integrated with spring, which allows Java developers to achieve the same development efficiency as. NET developers. Xfire is an open-source framework provided by codehaus. It builds a bridge between pojo and SOA. Its main feature is to support publishing pojo into a web service in a very simple way, this processing method not only gives full play to the role of pojo, simplifies the steps and processes for converting Java applications into web services, but also directly reduces the difficulty of SOA implementation, it provides a simple and feasible way for enterprises to switch to the SOA architecture. Next we will use a small example to implement a xfire-based WebService program.


Development Environment


Sun Java 6 + myeclipse 8.5

First, create a WebServiceEngineering: File-New-Web Service Project





Enter the name of the project you want. Select framework as xfire and click Next




The servlet class in the figure selects the current servlet. You can use other methods by default. Click Next. Select the current jar package.



Let's take a look at it.Organizational structure of the newly created mywebservice Web Service Project, The Web service project is very similar to a standard myeclipse WEB Project (this is the servlet configuration that myeclipse gave me when we just configured ):



 


Structure of the entire project:


OK. After most preparations are completed before development. The next step is to develop the WebService server, that is, the service end. In fact, the development mentioned here basically depends on the myeclipse Wizard to help us complete.

File-New-Other:




Find the Web service in Web Services in the myeclipse folder in the figure. Selected. Click Next.




The project in is the web project for which we want to create a service. Here, of course, we selected the mywebservice we just created. Note that strategy is selected as the second one: create a web service from the Java class, and select create a new Java Bean below. Click Next




Here, Let's enter a name for creating a web service. Select the package name of the generated class. Other Default values are good. Click Finish.



This wizard generates the imywebserviceservice Java interface and mywebserviceserviceimpl Java class. and in services. an object () is created in the XML configuration file. Note that the example (string name) method is generated in the interface class and is used as a test operation after the Web Service is deployed.

From the code above, we can see that the function of our web service is that when the client sends a "name" to me ". We return an "Hell + name ";


The next step is to release our web service program to the server. Only released to the program. Other people can call the services we write through interfaces. I will not write down the server publishing process. Then start the server.


OK. The web service has been written. Myeclipse provides us with a good web service testing function. Next we will use this function to test whether the write configuration of our Web Service is correct.


Select toolbar button in myeclipse perspective to execute web service Explorer

1. CLICK:

2. Select the WSDL mode:
3. type the URL-http: // localhost: 8080/mywebservice/services/mywebserviceservice of the mywebserviceservice WSDL document in the activity panel? WSDL, Web Service Explorer will download the automatically generated WSDL document, which is composed of xfire framework and produces a series of operations that can call the service.



4. Select the example operation in the activity panel and type mywebservice in in0 domain




5. Select the go button to call the example operation on mywebserviceservice. The result is displayed on the Status panel.

OK, we can find that. Our services are successful. This is successful. We can publish it to the network. Let the people who need this function call me. So how can we call this function? This involves the development of our WebService client. Let's take a look at the development of the WebService client.


For ease of understanding. We still create a client in our web project. First, we need to add support for the WebService client to my project. That is, add the required jar package.

Right-click Project-> buildpath-> Add libary-> select xfire1.2http-client libary



Finish


Create a test class:

This Code defines the process of creating an xfire Web Service proxy. This proxy supports the pojo imywebserviceservice interface. Run the above Code. We successfully called the Web service function we wrote.


Bytes ------------------------------------------------------------------------------------------------------------

The electronic book "Java programmers from stupid birds to cainiao" is officially released. You are welcome to download it.

Http://blog.csdn.net/csh624366188/article/details/7999247



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.