Use webservice in Java to simplify development (xfire webservice) and webservicexfire

Source: Internet
Author: User

Use webservice in Java to simplify development (xfire webservice) and webservicexfire

First, import the jar file to the project,

Xbean-spring-2.8.jar, wsdl4j-1.6.1.jar, commons-httpclient-3.0.jar, commons-codec-1.3.jar, xfire-all-1.2.6.jar, xmlschema-1.1.jar, spring-1.2.6.jar,

Commons-logging-1.0.4.jar, jdom-1.0.jar, these 9 packages are the main package for xfire implementing webservice on the server side, including accessing webservice and generating webservice

 

1. Access the webservice file:

  

Public static String visit (String method, Object [] params) throws Exception {Client client Client = new client (new URL (URL_SPAC); Client. setTimeout (5000); // access timeout for more than 5 seconds // set the access method and parameter Object [] results = client. invoke (method, params); return results [0]. toString ();}

It's easy, just a few lines of code. URL_space is http: // xxx: 8080/WebServices/xxx. asmx? WSDL is the access address of webservice, but must be? Wsdl

Currently, array parameters are not used by the caller.

 

2. Generate webservice

Create a new META-INF/xfire/services. xml file under src, which writes

<? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://xfire.codehaus.org/config/1.0"> <service> <name> webservice name </name> <serviceClass> java Interface Class path </serviceClass> <implementationClass> java interface implementation class path </implementationClass> <style> wrapped </style> <use> literal </use> <scope> application </scope> </service> </bean>

Configure and start the xfire servlet class in web. xml. The Code is as follows:

<servlet>  <servlet-name>XFireServlet</servlet-name>  <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>  <load-on-startup>0</load-on-startup> </servlet> <servlet> <servlet-mapping>  <servlet-name>XFireServlet</servlet-name>  <url-pattern>/services/*</url-pattern> </servlet-mapping>

In this way, a webservice named webservice is started.

 

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.