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.