How to Use xfire to develop WebService in eclipse and precautions

Source: Internet
Author: User

 

I am using eclipse3.5 + tomcat7.0 + xfire1.2.6. The following is the development method of the common server.

 

 

 

Finally, I completed a WebService example using Java. One of the very few problems left me alone for nearly a day. The following describes how to develop WebService on the Java platform.

Tool used: eclipse3.1.2 + tomcat5.5 + xfire1.1. It should be said that it is very easy to develop WebService using xfire. You only need to follow the steps below:

(1) create a dynamic web project in eclipse, assuming the name is xfiretest.

(2) import the xfire user library. This library should contain xfire-1.1 files under the xfire-all-1.1.jar directory, andXfire-1.1 \ LibAll files in the directory.

(3) Copy all the files in the above xfire user Library toWebcontent \ WEB-INF \ LibDirectory.

(4) modifyWebcontent \ WEB-INF \ WEB. xmlThe content of the configuration file. The following is the 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>
Xfirezhuweitest </display-Name>
<Welcome-file-List>
<Welcome-File> index.html </welcome-File>
<Welcome-File> index.htm </welcome-File>
<Welcome-File> index. jsp </welcome-File>
<Welcome-File> default.html </welcome-File>
<Welcome-File> default.htm </welcome-File>
<Welcome-File> default. jsp </welcome-File>
</Welcome-file-List>

<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-mapping>
<Servlet-Name> xfireservlet </servlet-Name>
<URL-pattern>/services/* </url-pattern>
</Servlet-mapping>

</Web-app>

Web. the servlet ing added in XML indicates that all URL requests that match "/services/" and "/servlet/xfireservlet/*" are forwarded to Org. codehaus. xfire. transport. HTTP. xfireconfigurableservlet.

(5) Compile a Java class that needs to be published as WebService. In this example, it is a very simple helloworldsimple. java. Put it under SRC under eclipse.

Package com. xfire;
Public class myservice
{
Public int add (int A, int B)
{
Return A + B;
}
}

(6) InWebcontent \ META-INFCreate a directoryXfire folderAdd the xfire configuration file services. xml under the xfire directory. The content of this configuration file reflects the Java classes to be published as Web Services. The content of services. XML in this example is as follows:

<Beans xmlns = "http://xfire.codehaus.org/config/1.0">
<Service>
<Name> helloworldsimple3 </Name>
<Namespace> http://webservice.xfire. simple2/helloworld </namespace>
<Serviceclass> WebService. xfire. simple2.helloworld </serviceclass>
<! -- <Scope> request </scope> -->
</Service>
Beans>

 

 

Xfire parses services. xml and extracts the configuration information that needs to be published as WebService.

Many articles have been introduced here, but when I start WebService according to what they call, and then use http: // localhost: 8080/xfiretest/services/helloworldsimple? WSDL (note that xfiretest is the project name and helloworldsimple is the service. when the <Name> value under <service> in XML, that is, the published service name, is used to access the service description, an exception is thrown. XML file does not exist --
"Org. springframework. beans. factory. beandefinitionstoreexception: ioexception parsing XML document from class path resource [META-INF/xfire/services. XML]; Nested exception is Java. io. filenotfoundexception: Class path resource [META-INF/xfire/services. XML] cannot
Be opened because it does not exist ".

(7) The key point is that it took me nearly one day to solve this problem.
InWebcontent \ WEB-INFCreate a directoryClassesFolderWebcontentThe entireMETA-INFFolder to the new classes folder.
The complete directory structure of the project is as follows:

(8) In package explorer, right-click the xfirezhuweitest project and choose run as> run on server to associate it with Tomcat on your machine. Then, Tomcat is started to start Web Services. (Note: Stop Tomcat before proceeding to this step)

(9) In IE, enter http: // localhost: 8080/xfirezhuweitest/services/mathservice? WSDL will get the correct Web Service Description document.

(10) Test the released WebService. I use C # To dynamically call Web Services:

// C #
String url = "http: // localhost: 8080/xfirezhuweitest/services/mathservice ";
Object [] ARGs = {1, 2 };
Object result = esframework. WebService. webservicehelper. invokewebservice (URL, "add", argS );
MessageBox. Show (result. tostring ());

(For details about C # Dynamic Web service calling, refer to here)

After execution, a dialog box is displayed. The result is 3.

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.