Using Xfire to develop WebService on eclipse

Source: Internet
Author: User
Tags web services xmlns

Finally, using Java to complete a webservice example, one of the very small problems that has plagued me for nearly a day. The steps below show how to develop WebService on the Java platform.

Tools used: Eclipse3.1.2 + Tomcat5.5 + XFire1.1. Using Xfire development WebService should be said to be very easy, just follow the steps in the following example:

(1) Create a new dynamic Web Project in Eclipse, assuming the name Xfirezhuweitest.

(2) Import the Xfire user library. The library should contain Xfire-all-1.1.jar files in the xfire-1.1 directory, and all files in the Xfire-1.1\lib directory.

(3) Copy all the files in the Xfire user library to the Webcontent\web-inf\lib directory of the Xfirezhuweitest project.

(4) Modify the contents of the Webcontent\web-inf\web.xml configuration file, the following is modified Web.xml:

<?xml version= "1.0" encoding= "UTF-8"
<web-app id= "webapp_id" version= "2.4" xmlns= "http://" Java.sun.com/xml/ns/j2ee "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http:// JAVA.SUN.COM/XML/NS/J2EE http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "
<display-name>
XFire Zhuweitest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome -file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</w Elcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>defaul T.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-li St>

<servlet>
<servlet-name>xfireservlet</servlet-name>
; servlet-class>
Org.codEhaus.xfire.transport.http.XFireConfigurableServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xfireservlet</servlet-name>
<url -pattern>/servlet/xfireservlet/*</url-pattern>
</servlet-mapping>

<servlet-mapp Ing>
<servlet-name>xfireservlet</servlet-name>
<url-pattern>/services/*& Lt;/url-pattern>
</servlet-mapping>

</web-app>

The servlet mappings added in web.xml indicate that all matches "/services/*" URL request all to Org.codehaus.xfire.transport.http.XFireConfigurableServlet to deal with.

(5) Write Java classes that need to be published as WebService, a very simple mathservice.java in this example.

package com.zhuweisky.xfireDemo;
public class MathService
{
     public int Add(int a ,int b)
     {
         return a+b ;
     }
}

(6) Create a new Xfire folder in the Webcontent\meta-inf directory, and then add a Xfire profile services.xml in the Xfire directory that reflects which Java classes to publish as Web services. The services.xml in this example reads as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
     <service>
       <name>MathService</name>
       <namespace>http://com.zhuweisky.xfireDemo/MathService</namespace>
       <serviceClass>com.zhuweisky.xfireDemo.MathService</serviceClass>
     </service>
</beans>

Related Article

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.